#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int i,j;
int a[11][11]; //数组要大于10,否则会溢出,这是选11不选10的原因
for (i = 1; i < 11; i++)
{
for (j = 1;j < i+1; j++)
if(i==j||j==1)
{
a[i][j]=1;
}
else
{
a[i][j]=a[i-1][j-1]+a[i-1][j];
}
}
cout<<"the yanghui triangle of 10 is :"<<endl;
for (i = 1; i < 11; i++)
{
for (j = 1;j <i+1; j++)
{
cout<<setw(4)<<a[i][j];
}
cout<<endl;
}
cout<<endl;
return 0;
}
答案: