题解 | 杨辉三角
杨辉三角
https://www.nowcoder.com/practice/8c6984f3dc664ef0a305c24e1473729e
#include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; int a[n][n]; for (int i = 0; i < n; i++) { a[i][0] = 1; a[i][i] = 1; } for (int i = 2; i < n; i++) { for (int j = 1; j < i; j++) { a[i][j] = a[i - 1][j] + a[i - 1][j - 1]; } } for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { cout << a[i][j] << " "; } cout << endl; } }