杨辉三角

#include<iostream>
using namespace std;
int main()
{
const int m=15;
int a[m][m],i,j;//int a[9][9]9行9列的二位数组,a[0][0]~a[8][8],因此下面输出数组内容到a[9][9]会异常,利用VC++编译结果正常显示但
//提示程序未正常运行一般就是指针和数组越界的问题。利用常量做数组下标是个好习惯
for( i=0;i<m;i++)
{
a[i][0]=1;
a[i][i]=1;


for(j=1;i>j;j++)
a[i][j]=a[i-1][j-1]+a[i-1][j];
}


for(i=0;i<m;i++)
{
{
for(j=0;j<=i;j++)
cout<<a[i][j]<<"  ";
}
cout<<endl;
}
return 0;
}
/*
#include<iostream.h>
#include<iomanip.h>
void main()
{
const int m=10;
int a[m][m],i,j;
for(i=0;i<m;i++)
{
a[i][0]=1;
a[i][i]=1;
for(j=1;j<i;j++)
a[i][j]=a[i-1][j-1]+a[i-1][j];
}
for(i=0;i<m;i++)
{
for(j=0;j<=i;j++)
{
cout<<a[i][j]<<setw(5);
}
cout<<endl;
}
}
*/
posted @ 2014-03-27 18:17  lz3018  阅读(122)  评论(0编辑  收藏  举报