#include <iostream>
#include <iomanip>
#include <windows.h>
#include <fstream>
#include <string>
using namespace std;
#define N 10
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; }
posted on 2022-09-01 19:05  wshidaboss  阅读(46)  评论(0编辑  收藏  举报