小王子中英文:菜鸟求教C++数组问题,老鸟帮忙改下

来源:百度文库 编辑:高校问答 时间:2024/04/23 18:24:41
//杨辉三角

#include<iostream.h>
//为什么执行到第2行就不往下走了呢?郁闷!拜托帮帮忙吧!
void main()
{
int h,l;
int a[19][20];
for(h=0;h<=18;h++)
{
for(l=0;l<=18;l++)
{
a[h][l]=0;
}
} //把所有的都负值为0;
int s,b;
cout<<"输入行数:";
cin>>s;
a[0][s-1]=1;
for(b=1;b<=s-1;b++)
{
cout<<" ";
}
cout<<a[0][s-1]<<endl; // 输出第一行,算空格在内,最上边的数的列数=行数
// 这之前都是格式的问题,关键是后边的
a[s][0]=1; // 最后1行的第一个数赋值成1
for(h=1;h<=9;h++)
{
for(l=0;l<=18;l++)
a[h][l+1]=a[h-1][l]+a[h-1][l+2]; //按照定义就是这个样子啊

if(a[h][l]==0)
cout<<" ";
else
if(a[h][l]<10)
cout<<" "<<a[h][l];
else
cout<<a[h][l];
}
cout<<endl;
}

#include<iostream.h>
void main()
{
int i,j;
int a[5][5];
for(i=0;i<=4;i++)
{
for(j=0;j<=4;j++)
{
if(i%2==0)
a[i][j]=5*i+j+1;
else
a[i][4-j]=5*i+j+1;
if(a[i][j]>=10)
cout<<a[i][j];
else cout<<" "<<a[i][j];
}
}
}