在屏幕上打印杨辉三角。
1
1 1
1 2 1
1 3 3 1
#include<stdio.h>
int main() {
int row=0, col=0;
int arr[20][20] = { 0 };
arr[0][0] = 1;
printf("%d\n",arr[0][0]);
for (row = 1; row < 10; ++row) {
arr[row][0] = 1;
printf("%d “, arr[row][0]);
for (col = 1; col <= row; ++col) {
if (row == col) {
arr[row][col] = 1;
}
arr[row][col] = arr[row - 1][col - 1] + arr[row - 1][col];
printf(”%d ", arr[row][col]);
}
putchar(’\n’);
}
return 0;
}
这是一个二维数组写出来的杨辉三角 感兴趣的老铁可以试试一维数组写杨辉三角奥!