![]() |
#2
mxs8102010-07-29 11:50
|

#include<iostream.h>
void main()
{
int num[6]={5,7,3,4,2,1};
int i,j,k,temp;
int ans[6][6];
for(j=0;j<6;j++)
{
i=0;
ans[i][j]=num[j];
temp=num[j];
for(k=1;k<=6;k++)
{
i++;
j++;
if(j>5)
{
j-=6;
}
ans[i][j]=temp;
// cout<<"k="<<k<<endl;
cout<<"j="<<j<<'\t';
}
cout<<endl;
// cout<<"j="<<j<<endl;
}
for(i=0;i<6;i++)
{
for(j=0;j<6;j++)
cout<<ans[i][j]<<'\t';
cout<<endl;
}
}
运行结果:void main()
{
int num[6]={5,7,3,4,2,1};
int i,j,k,temp;
int ans[6][6];
for(j=0;j<6;j++)
{
i=0;
ans[i][j]=num[j];
temp=num[j];
for(k=1;k<=6;k++)
{
i++;
j++;
if(j>5)
{
j-=6;
}
ans[i][j]=temp;
// cout<<"k="<<k<<endl;
cout<<"j="<<j<<'\t';
}
cout<<endl;
// cout<<"j="<<j<<endl;
}
for(i=0;i<6;i++)
{
for(j=0;j<6;j++)
cout<<ans[i][j]<<'\t';
cout<<endl;
}
}
只有本站会员才能查看附件,请 登录
大家看看,这是我的错呢,还是计算机的错?
注意运行结果中第三行中j的变化,我认为有问题~