C program to create a Pyramid or Pettern.
source code:
- #include<stdio.h>
- void main()
- {
- int i, j, k, rows;
- printf("Enter number of rows : ");
- scanf("%d", &rows);
- for ( i = 0; i < rows; i++ )
- {
- //Display spaces before the *
- for( j = 0 ; j < (rows - i); j++ )
- printf(" ");
- //Display *
- for ( k = 0; k < (2*i + 1) ; k++)
- printf("*");
- printf("\n");
- }
- }
Output:
Enter number of rows : 5
*
***
*****
*******
*********
0 comments:
Post a Comment