mirror of
https://github.com/renbaoshuo/202401-programming-assignments.git
synced 2024-11-23 15:48:42 +00:00
34 lines
531 B
C
34 lines
531 B
C
|
void hollowPyramid(int n) {
|
||
|
if (n == 1) {
|
||
|
printf("1\n");
|
||
|
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
for (int i = 1; i < n; i++) {
|
||
|
printf(" ");
|
||
|
}
|
||
|
|
||
|
printf("%d\n", 1);
|
||
|
|
||
|
for (int i = 2; i < n; i++) {
|
||
|
for (int j = 1; j <= n - i; j++) {
|
||
|
printf(" ");
|
||
|
}
|
||
|
|
||
|
printf("%d", i);
|
||
|
|
||
|
for (int j = 1; j <= (i - 1) * 2 - 1; j++) {
|
||
|
printf(" ");
|
||
|
}
|
||
|
|
||
|
printf("%d\n", i);
|
||
|
}
|
||
|
|
||
|
for (int i = 1; i < n * 2; i++) {
|
||
|
printf("%d", n);
|
||
|
}
|
||
|
|
||
|
printf("\n");
|
||
|
}
|