Pattern 5 : Pyramid star pattern program in C | C Program to print pyramid star pattern

Spread the love
Pattern 5: Write a C Program to print below pattern ( Pyramid Star pattern without spaces).

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

Explanation:

I am using four for loops to print above pattern. First for loop is responsible for number of rows. I also divided this pattern into three parts as shown in below image. And remaining three inner for loops are responsible for printing these three parts.

Program :

  1. #include<stdio.h>
  2. int main()
  3. {
  4.    int i,j,n;
  5.    printf(“Enter how many rows you want: “);
  6.    scanf(“%d”,&n);
  7.  
  8.    for(i=1;i<=n;i++)       // for loop 1
  9.    {
  10.       for(j=1;j<=(ni);j++)   // for loop 2
  11.          printf(” “);   // one space only 
  12.  
  13.       for(j=1;j<=i;j++)      // for loop 3
  14.          printf(“*”);
  15.      
  16.       for(j=1; j<; j++)    // for loop 4
  17.          printf(“*”);
  18.  
  19.       printf(n);
  20.    } // outer for loop, for rows
  21.    return 0;
  22. }

Output:

Pyramid Pattern program without spaces

Similar Star pattern 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