Pattern 15: C Program to print Irregular polyhedron star pattern with out spaces.

Spread the love

Write a C program to print the following pattern using for loops:

* * * * *
 * * * *
  * * *
   * *
    *
    *
   * *
  * * *
 * * * *
* * * * *

Note: This program is the similar program to Pattern 14 but without the spaces in between two triangles.

Here I am using continue keyword, It will take the execution of the program to next iteration on other words it simply skips the execution of present iteration and goes to next iteration. So in pattern 14 program iteration 0 is causing spaces, So I am just skipping that iteration by using continue.

Program:

  1. #include<stdio.h>
  2. int main()
  3. {
  4.    int i,j,k,num;
  5.    printf(“Enter any value : “);
  6.    scanf(“%d”,&num);
  7.  
  8.    for(i=-num;i<=num;i++)
  9.    {
  10.       if(i==0)
  11.         continue;
  12.       k=i;
  13.       if(k>0)
  14.       {
  15.          k = k * 1;
  16.       }
  17.       for (= 0; j < num; ++j)
  18.       {
  19.          if (< (k+num))
  20.          {
  21.             printf(” “);
  22.          }
  23.          else
  24.          {
  25.             printf(“* “);
  26.          }
  27.       }
  28.       printf(n);
  29.    }
  30.    return 0;
  31. }

Output :

Note: If you want spaces in between two triangles just delete continue statement in the loop, Please Refer to the following post for more details. “Polyhedron with spaces”.

Related Programs :

More C programs:

C Tutorials with simple Examples:

Venkatesh Macha

Hi Guys, I am Venkatesh Macha. I am a programmer and an Open Source enthusiast, Presently working as a Software Engineer. Apart from that, I love to explore new technologies and things.

You may also like...

Leave a Reply