Skip to content

Commit 94468fd

Browse files
authored
Diamond star pattern
Diamond star pattern using c
1 parent 6be80a8 commit 94468fd

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Diff for: Star Pattern

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <stdio.h>
2+
int main(void) {
3+
int n;
4+
printf("Enter the number of rows\n");
5+
scanf("%d",&n);
6+
int spaces=n-1;
7+
int stars=1;
8+
for(int i=1;i<=n;i++)
9+
{
10+
for(int j=1;j<=spaces;j++)
11+
{
12+
printf(" ");
13+
}
14+
for(int k=1;k<=stars;k++)
15+
{
16+
printf("*");
17+
}
18+
if(spaces>i)
19+
{
20+
spaces=spaces-1;
21+
stars=stars+2;
22+
}
23+
if(spaces<i)
24+
{
25+
spaces=spaces+1;
26+
stars=stars-2;
27+
}
28+
printf("\n");
29+
}
30+
return 0;}

0 commit comments

Comments
 (0)