船长上单怕什么:将二维数组 a表示的矩阵转置存b中,并输入a和b。

来源:百度文库 编辑:高校问答 时间:2024/04/29 05:42:58
将二维数组 a表示的矩阵转置存b中,并输入a和b。
运行结果是
before changed ;a
1 4 7 10
2 5 8 11
3 6 9 12
after changed :b
1 2 3
4 5 6
7 8 9
10 11 12

#include<iostream>
using namespace std;
int a[100][100],b[100][100];
int main(){
for(int m,n; cin>>m>>n; ){//输入矩阵大小M*N
//输入a和b?弄错了吧,输入a就已知b了
for(int i=0; i<m; i++)
for(int j=0; j<n; j++){
cin>>a[i][j];//输入a
b[i][j]=a[j][i];//求出b
}
//输出a,b
cout<<"a:"<<endl;
for(int i=0; i<m; i++){
for(int j=0; j<n; j++)
cout<<a[i][j];
cout<<endl;
}
cout<<"b:"<<endl;
for(int i=0; i<m; i++){
for(int j=0; j<n; j++)
cout<<b[i][j];
cout<<endl;
}
}
}