题解 | #杨辉三角#
杨辉三角
https://www.nowcoder.com/practice/e671c6a913d448318a49be87850adbcc
#include <stdio.h> #define N 30 int main() { int n = 0; while (1 == scanf("%d", &n)) { int arr[N][N] = {0}; for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { if (!j || (i == j)) { arr[i][j] = 1; } else if (i >= 2 && j > 0) { arr[i][j] = arr[i - 1][j] + arr[i - 1][j - 1]; } printf("%5d", arr[i][j]); } printf("\n"); } } return 0; }