题解 | #杨辉三角#
杨辉三角
https://www.nowcoder.com/practice/e671c6a913d448318a49be87850adbcc
#include <stdio.h> int main() { int arr[30][30] = {0}; int i = 0; int j = 0; int n = 0; scanf("%d", &n); for (i = 0; i < n; i++) { for (j = 0; j <= i; j++) { if (i == j) arr[i][j] = 1; if (j == 0) arr[i][j] = 1; if (i > 1 && j > 0) arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j]; } } for (i = 0; i < n; i++) { for (j = 0; j <= i; j++) { printf("%5d", arr[i][j]); } printf("\n"); } return 0; }
c语言刷题 文章被收录于专栏
c语言刷题题目