Skip to content

Commit f587b48

Browse files
pattern
1 parent acf085d commit f587b48

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

diamond.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
3+
Program in C to print the Hollow Number Diamond Pattern
4+
5+
Sample Input:
6+
7+
4
8+
9+
Sample Output:
10+
11+
*
12+
* *
13+
* *
14+
* *
15+
* *
16+
* *
17+
* *
18+
* *
19+
*
20+
21+
--------------------------------
22+
23+
*/
24+
#include<stdio.h>
25+
int main()
26+
{
27+
printf("Enter the number of rows to show the star pattern: ");
28+
int n, x, y, s = 1, k;
29+
scanf("%d",&n);
30+
for(x = 0; x <= n; x++)
31+
{
32+
for(y = n; y > x; y--)
33+
{
34+
printf(" ");
35+
}
36+
printf("*");
37+
if (x > 0)
38+
{
39+
for(k = 1; k <= s; k++)
40+
{
41+
printf(" ");
42+
}
43+
s += 2;
44+
printf("*");
45+
}
46+
printf("\n");
47+
}
48+
s -= 4;
49+
for(x = 0; x <= n -1; x++)
50+
{
51+
for(y = 0; y <= x; y++)
52+
{
53+
printf(" ");
54+
}
55+
printf("*");
56+
for(k = 1; k <= s; k++)
57+
{
58+
printf(" ");
59+
}
60+
s -= 2;
61+
if(x != n -1)
62+
{
63+
printf ("*");
64+
}
65+
//ending line after each row
66+
printf("\n");
67+
}
68+
return 0;
69+
}

0 commit comments

Comments
 (0)