题解 | #矩阵转置#
矩阵转置
https://www.nowcoder.com/practice/0fe4d131737d4138912c3b5df8569245
#include <iostream> using namespace std; const int MAXN = 100 + 10; int matrix[MAXN][MAXN]; int main () { int n; while (cin >> n){ for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ cin >> matrix[i][j]; } } int temp; for (int i = 0; i < n; i++){ for (int j = i + 1; j < n; j++){ swap(matrix[i][j], matrix[j][i]); } } for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ cout << matrix[i][j] << " "; } cout << endl; } } return 0; }