C program to create a Pyramid or Pettern.

source code:

  1. #include<stdio.h>

  2. void main()
  3. {
  4. int i, j, k, rows;
  5. printf("Enter number of rows : ");
  6. scanf("%d", &rows);
  7. for ( i = 0; i < rows; i++ )
  8. {
  9. //Display spaces before the *
  10. for( j = 0 ; j < (rows - i); j++ )
  11.    printf(" ");
  12. //Display *
  13. for ( k = 0; k < (2*i + 1) ; k++)
  14.    printf("*");
  15. printf("\n");
  16. }
  17. }

Output:

Enter number of rows : 5
     *
    ***
   *****
  *******
 *********

0 comments:

Post a Comment