Pattern 14 : C Program to print Irregular polyhedron star pattern

Spread the love

Write a C Program to print below pattern using for loop:

* * * * *
 * * * *
  * * *
   * *
    *
 
    *
   * *
  * * *
 * * * *
* * * * *
Note: This is one the Series of pattern programs in C.

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.    for(i=-num;i<=num;i++)
  8.    {
  9.       k=i;
  10.       if(k>0)
  11.       {
  12.          k = k * 1;
  13.       }
  14.       for (= 0; j < num; ++j)
  15.       {
  16.          if (< (k+num))
  17.          {
  18.             printf(” “);  // One Space only
  19.          }
  20.          else
  21.          {
  22.             printf(“* “); // One Star, One Space.
  23.          }
  24.       }
  25.       printf(n);
  26.    }
  27.    return 0;
  28. }

Output:

Note : If you don’t want spaces in between two triangles just add one continue statement in the loop, Please Refer to the following post for more details. “Polyhedron without 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