Problem:  Write a c program to print Pyramid Patterns.
 
        *
        * * *
        * * * * *
        * * * * * * *
         * * * * * * * * *
Source Code:
  1.  /*
  2. * C Program to print full pyramid pattern using *
  3. */
  4. #include<stdio.h>
  5. #include<conio.h>
  6. int main()
  7.  {
  8.     int row, space, rows, star=0;
  9.     printf("Enter the number of rows in pyramid\n");
  10.     scanf("%d",&rows);
  11.  
  12.     for(row = 1;row <= rows; row++)
  13. {
  14.      /* Printing spaces */
  15.         for(space = 1; space <= rows-row; space++) 
  16. {
  17.            printf("  ");
  18.         }
  19.         /* Printing stars */
  20.         while(star != (2*row - 1)) 
  21. {
  22.             printf("* ");
  23.             star++;;
  24.         }
  25.         star=0;
  26.         printf("\n");
  27.     }
  28.     getch();
  29.     return 0;
  30. }
Outputs:
         

0 comments:

Post a Comment