1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-11-27 08:26:20 +00:00
202401-programming-assignments/【实践课内】11.函数2/6-4 空心的数字金字塔.c

34 lines
531 B
C
Raw Normal View History

2024-11-22 08:22:46 +00:00
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");
}