-
Notifications
You must be signed in to change notification settings - Fork 1
/
starpatterns.c
104 lines (94 loc) · 1.77 KB
/
starpatterns.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <stdio.h>
void starpattern(int rows)
{
for (int i = 0; i < rows; i++)
{
for (int j = 0; j <= i; j++)
{
printf("*");
}
printf("\n");
}
}
void revstarpattern(int rows)
{
for (int i = 0; i < rows; i++)
{
for (int j = rows; j > i; j--)
{
printf("*");
}
printf("\n");
}
}
void pyramid(int rows)
{
int min_star = 1;
int x = rows;
int y = x - 1;
int k;
for (int i = 0; i < x; i++)
{
for (int j = y; j > i; j--)
{
printf(" ");
}
for (k = 0; k < min_star; k++)
{
printf("*");
}
min_star += 2;
printf("\n");
}
}
void pyramid_1(int rows)
{
int n = rows;
int px = n;
int py = n;
int i, j;
for (i = 1; i <= n; i++)
{
for (j = 1; j < n * 2; j++)
{
if (j >= px && j <= py)
{
printf("*");
}
else
{
printf(" ");
}
}
px--;
py++;
printf("\n");
}
}
int main()
{
int rows, type;
printf(" press 0 for starpattern and 1 for reverse starpattern , 2 for pyramid, 3 for pyramid_1.\n");
scanf("%d", &type);
printf(" how many rows you want?\n");
scanf("%d", &rows);
switch (type)
{
case 0:
starpattern(rows);
break;
case 1:
revstarpattern(rows);
break;
case 2:
pyramid(rows);
break;
case 3:
pyramid_1(rows);
break;
default:
printf("Invalid Input.");
break;
}
return 0;
}