Thursday, 26 March 2015

Print Pyramid structure in C



 

    *
   ***
  *****
 *******
*********
We have shown five rows above, in the program you will be asked to enter the numbers of rows you want to print in the pyramid of stars.
C programming code
#include <stdio.h>
#include <conio.h>

void main()
{
   int row, c, n, temp;
   clrscr();
   printf("Enter the number of rows in pyramid of stars you wish to see ");
   scanf("%d",&n);

   temp = n;

   for ( row = 1 ; row <= n ; row++ )
   {
      for ( c = 1 ; c < temp ; c++ )
         printf(" ");

      temp--;

      for ( c = 1 ; c <= 2*row - 1 ; c++ )
         printf("*");

      printf("\n");
   }

   getch();
}



No comments:

Post a Comment