题解 | #矩阵转置#
矩阵转置
https://www.nowcoder.com/practice/0fe4d131737d4138912c3b5df8569245
#include <iostream>
using namespace std;
const int N = 110;
int g[N][N];
int main(){
int n;
cin>>n;
for(int i = 0; i < n; i ++)
for(int j = 0; j < n; j ++)
cin>>g[i][j];
for(int i = 0; i < n; i ++)
for(int j = 0; j < i; j ++){
int tmp = g[j][i];
g[j][i] = g[i][j];
g[i][j] = tmp;
}
for(int i = 0; i < n; i ++){
for(int j = 0; j < n; j ++){
cout<<g[i][j]<<' ';
}
cout<<endl;
}
return 0;
}
