-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4.c
59 lines (45 loc) · 1.01 KB
/
4.c
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
*
***
*****
*******
*******
*****
***
*
*/
#include <stdio.h>
int main()
{
int row;
// take the row number as input
printf("Enter the number of row(s) : ");
scanf("%d", &row);
/*** print first half of the pattern ***/
// run one loop for row(s) from i = 1 to i = row
for (int i = 1; i <= row; i++)
{
// print spaces (row - i) times
for (int j = 1; j <= row - i; j++)
printf(" ");
// print '*'
for (int j = 1; j <= 2 * i - 1; j++)
printf("*");
// print one new line
printf("\n");
}
/*** print second half of the pattern ***/
// run one loop for row(s) from i = row to i = 1
for (int i = row; i >= 1; i--)
{
// print spaces (row - i) times
for (int j = 1; j <= row - i; j++)
printf(" ");
// print '*'
for (int j = 1; j <= 2 * i - 1; j++)
printf("*");
// print one new line
printf("\n");
}
return 0;
}