#include<iostream>
#include<iomanip>
#define M 7
#define N 8
using namespace std;
int main()
{
int a[M][N] = {0,0};//赋初始值,让所有的数据都为0
a[0][1] = 1;//赋第一行第二个数据为1
int i, j, k;
//将整个三角形向右移一列
for (i = 1; i < M; i++)
{
for (j = 1; j < i+2; j++)
{
a[i][j] = a[i - 1][j] + a[i - 1][j - 1];//找规律一个数据的值为上一行同列和前一列的和,所以需要向右移动一列
}
}
cout << "------------杨辉三角-------------"<<endl;
for (i = 0; i < M; i++)
{
k = N - 1 - i;//找规律输出一定单位的空格
for (; k > 0; k--)
{
cout << setw(2)<<" ";
}
for (j = 1; j < i+1; j++)//由于向右移动一个单位,输出从第二列输出
{
cout << setw(4)<<a[i][j];
}
cout << endl;
}
}