怎样解杨辉三角?

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/03 03:28:16
怎样解杨辉三角?

怎样解杨辉三角?
怎样解杨辉三角?

怎样解杨辉三角?
性质
1、每行数字左右对称,由1开始逐渐变大,然后变小,回到1.
2、第n行的数字个数为n个.
3、第n行数字和为2^(n-1).
4、每个数字等于上一行的左右两个数字之和.可用此性质写出整个帕斯卡三角形.
5、将第2n+1行第1个数,跟第2n+2行第3个数、第2n+3行第5个数……连成一线,这些数的和是第2n个斐波那契数.将第2n行第2个数,跟第2n+1行第4个数、第2n+2行第6个数……这些数之和是第2n-1个斐波那契数.
6、第n行的第1个数为1,第二个数为1×(n-1),第三个数为1×(n-1)×(n-2)/2,第四个数为1×(n-1)×(n-2)/2×(n-3)/3…依此类推.

#include
#include
using namespace std;
void main()
{
int i,j;
int a[11][22];
for(i=0;i<11;i++)
for(j=0;j<22;j++)
a[i][j]=0;
...

全部展开

#include
#include
using namespace std;
void main()
{
int i,j;
int a[11][22];
for(i=0;i<11;i++)
for(j=0;j<22;j++)
a[i][j]=0;
cout< a[0][10]=1;
a[1][11]=1;
a[1][9]=1;
for(i=2;i<11;i++)
for(j=0;j<22;j++)
a[i][j]=a[i-1][j-1]+a[i-1][j+1];
for(i=0;i<10;i++)
{
for(j=0;j<22;j++)
{ if(a[i][j]==0)
cout<else
cout<}
cout<}
}

收起