Run ID:119652

提交时间:2025-05-18 11:01:07

#include <iostream> using namespace std; int main() { int n = 3; int a[3][3]; int b[3][3]; // 输入矩阵a for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; } } // 正确转置:将a转置到b for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { b[i][j] = a[j][i]; // 将a的列变为b的行 } } // 输出转置后的矩阵b(每行最后无空格) for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cout << b[i][j]; if (j < n - 1) { cout << " "; } } cout << endl; } return 0; }