将一个2乘3的二维数组a的行和列元素互换,存到一个3乘2的二维数组b中 5
#include<iostream>usingnamespacestd;intmain(){inta[2][3]={{1,2,3},{4,5,6}};intb[3][2]...
#include<iostream>
using namespace std;
int main()
{int a[2][3]={{1,2,3},{4,5,6}};
int b[3][2],i,j;
cout<<"array a:"<<endl;
for(i=0;i<=1;i++)
{for(j=0;j<=2;j++)
cout<<a[i][j]<<" ";
b[j][i]=a[i][j];
cout<<endl;}
cout<<"array b:"<<endl;
for(i=0;i<=2;i++)
{for(j=0;j<=1;j++)
cout<<b[i][j]<<" ";
cout<<endl;
}
return 0;
}
结果:
array a:
1 2 3
4 5 6
array b:
-858993460 -858993460
-858993460 -858993460
-858993460 -858993460
请问各位朋友array b为什么会这样的 展开
using namespace std;
int main()
{int a[2][3]={{1,2,3},{4,5,6}};
int b[3][2],i,j;
cout<<"array a:"<<endl;
for(i=0;i<=1;i++)
{for(j=0;j<=2;j++)
cout<<a[i][j]<<" ";
b[j][i]=a[i][j];
cout<<endl;}
cout<<"array b:"<<endl;
for(i=0;i<=2;i++)
{for(j=0;j<=1;j++)
cout<<b[i][j]<<" ";
cout<<endl;
}
return 0;
}
结果:
array a:
1 2 3
4 5 6
array b:
-858993460 -858993460
-858993460 -858993460
-858993460 -858993460
请问各位朋友array b为什么会这样的 展开
3个回答
展开全部
主程序修改如下(见有注释那行):
int main()
{
int a[2][3]={{1,2,3},{4,5,6}};
int b[3][2],i,j;
cout<<"array a:"<<endl;
for(i=0;i<=1;i++)
{
for(j=0;j<=2;j++) //for 循环包含两行语句应加大括号
{ cout<<a[i][j]<<" ";
b[j][i]=a[i][j];
}
cout<<endl;
}
cout<<"array b:"<<endl;
for(i=0;i<=2;i++)
{
for(j=0;j<=1;j++)
cout<<b[i][j]<<" ";
cout<<endl;
}
return 0;
}
int main()
{
int a[2][3]={{1,2,3},{4,5,6}};
int b[3][2],i,j;
cout<<"array a:"<<endl;
for(i=0;i<=1;i++)
{
for(j=0;j<=2;j++) //for 循环包含两行语句应加大括号
{ cout<<a[i][j]<<" ";
b[j][i]=a[i][j];
}
cout<<endl;
}
cout<<"array b:"<<endl;
for(i=0;i<=2;i++)
{
for(j=0;j<=1;j++)
cout<<b[i][j]<<" ";
cout<<endl;
}
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<iostream>
using namespace std;
int main()
{int a[2][3]={{1,2,3},{4,5,6}};
int b[3][2],i,j;
cout<<"array a:"<<endl;
for(i=0;i<=1;i++)
{for(j=0;j<=2;j++)
{//这里加个大括号把下面两句放在一个快内
cout<<a[i][j]<<" ";
b[j][i]=a[i][j];
} //到这里
cout<<endl;}
cout<<"array b:"<<endl;
for(i=0;i<=2;i++)
{for(j=0;j<=1;j++)
cout<<b[i][j]<<" ";
cout<<endl;
}
return 0;
}
using namespace std;
int main()
{int a[2][3]={{1,2,3},{4,5,6}};
int b[3][2],i,j;
cout<<"array a:"<<endl;
for(i=0;i<=1;i++)
{for(j=0;j<=2;j++)
{//这里加个大括号把下面两句放在一个快内
cout<<a[i][j]<<" ";
b[j][i]=a[i][j];
} //到这里
cout<<endl;}
cout<<"array b:"<<endl;
for(i=0;i<=2;i++)
{for(j=0;j<=1;j++)
cout<<b[i][j]<<" ";
cout<<endl;
}
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<iostream>
using namespace std;
int main()
{int a[2][3]={{1,2,3},{4,5,6}};
int b[3][2],i,j;
cout<<"array a:"<<endl;
for(i=0;i<=1;i++)
{for(j=0;j<=2;j++)
cout<<a[i][j]<<" ";
b[j][i]=a[i][j];
cout<<endl;}
cout<<"array b:"<<endl;
for(i=0;i<=2;i++)
{for(j=0;j<=1;j++)
cout<<b[i][j]<<" ";
cout<<endl;
}
return 0;
}
结果:
array a:
1 2 3
4 5 6
array b:
using namespace std;
int main()
{int a[2][3]={{1,2,3},{4,5,6}};
int b[3][2],i,j;
cout<<"array a:"<<endl;
for(i=0;i<=1;i++)
{for(j=0;j<=2;j++)
cout<<a[i][j]<<" ";
b[j][i]=a[i][j];
cout<<endl;}
cout<<"array b:"<<endl;
for(i=0;i<=2;i++)
{for(j=0;j<=1;j++)
cout<<b[i][j]<<" ";
cout<<endl;
}
return 0;
}
结果:
array a:
1 2 3
4 5 6
array b:
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |