1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-12-03 17:26:21 +00:00
202401-programming-assignments/【实践课外】8.数组2/7-25 数组-杨辉三角.c

28 lines
456 B
C
Raw Normal View History

2024-11-13 03:09:36 +00:00
#include <stdio.h>
int n, f[25][25];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
f[i][1] = f[i][i] = 1;
}
for (int i = 2; i <= n; i++) {
for (int j = 2; j < i; j++) {
f[i][j] = f[i - 1][j - 1] + f[i - 1][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
printf("%7d", f[i][j]);
}
printf("\n");
}
return 0;
}