-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDiamondpattern.c
More file actions
40 lines (31 loc) · 778 Bytes
/
Diamondpattern.c
File metadata and controls
40 lines (31 loc) · 778 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
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
int main() {
int n, i, j, space;
printf("Enter the number of rows: ");
scanf("%d", &n);
// Upper part of the diamond
for (i = 1; i <= n; i++) {
// Print leading spaces
for (space = 1; space <= n - i; space++) {
printf(" ");
}
// Print asterisks
for (j = 1; j <= 2 * i - 1; j++) {
printf("*");
}
printf("\n");
}
// Lower part of the diamond
for (i = n - 1; i >= 1; i--) {
// Print leading spaces
for (space = 1; space <= n - i; space++) {
printf(" ");
}
// Print asterisks
for (j = 1; j <= 2 * i - 1; j++) {
printf("*");
}
printf("\n");
}
return 0;
}