-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathPyramid.c
More file actions
31 lines (29 loc) · 699 Bytes
/
Copy pathPyramid.c
File metadata and controls
31 lines (29 loc) · 699 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdio.h>
int main()
{
int i, space, rows, k=0; // declaration of variables
printf("Enter number of rows: ");
scanf("%d",&rows); //take the input from the user of the no of rows to print * in the pyramid
for(i=1; i<=rows; ++i, k=0)
{
for(space=1; space<=rows-i; ++space)
{
printf(" "); // print spaces in the pyramid
}
while(k != 2*i-1)
{
printf("* "); //printing * in the pyramid
++k;
}
printf("\n"); // next line of the pyramid
}
return 0;
}
/*Output Example
Enter number of rows: 5
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
*/