#include <iostream> #include <iomanip> #include <windows.h> #include <fstream> #include <string> using namespace std; #define N 10标签:int,C++,帕斯卡,杨辉三角,include,贾宪三角 From: https://www.cnblogs.com/smartlearn/p/16647571.html
int main() { int a[N][N] = { 0 }; for (int i = 0; i <N; i++) { for (int j = 0; j <=i; j++) { if (j==0 || i==j) { a[i][j] = 1; } else { a[i][j] = a[i - 1][j - 1] + a[i - 1][j]; } } }
for (int i = 0; i < N; i++) { cout << setw((N - i) * 2)<<a[i][0]; //设每个数字或每个空格占2个字符位 for (int j = 1; j <= i; j++) { cout << setw(4)<< a[i][j]; } cout << endl; }
system("pause"); return 0; }