-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17_diamond.c
More file actions
41 lines (29 loc) · 630 Bytes
/
17_diamond.c
File metadata and controls
41 lines (29 loc) · 630 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
41
#include <stdio.h>
#include <math.h>
void printDiamond(int n) {
int i, j, k;
for (i = 1; i <= n; i++) {
for (j = 1; j <= n - i; j++) {
printf(" ");
}
for (k = 9; k >= 9 - (2 * i - 2); k--) {
printf("%d ", k);
}
printf("\n");
}
for (i = n - 1; i >= 1; i--) {
for (j = 1; j <= n - i; j++) {
printf(" ");
}
for (k = 9; k >= 9 - (2 * i - 2); k--) {
printf("%d ", k);
}
printf("\n");
}
}
int main() {
int n;
scanf("%d", &n);
printDiamond(n);
return 0;
}