//3*3矩阵转置 //解题思路: //获得转置,a[1][2]变为a[2][1] #include<iostream> using namespace std; //void T(int a[3][3]) //{ // for (int i = 0; i<3; i++) // for (int j = 0; j<2; j++) // { // int temp; // temp = a[i][j]; // a[i][j] = a[j][i]; // a[j][i] = temp; // } //} int main() { /*int matrix[3][3] = { { 3, 4, 6 }, { 4, 45, 5 }, { 13, 3, 8 } };*/ int matrix[3][3]; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) cin >> matrix[i][j]; printf("原矩阵: "); for (int i = 0; i<3; i++){ for (int j = 0; j<3; j++) cout << matrix[i][j] << " "; cout << endl; } printf(" 转置后矩阵: "); //T(matrix); for (int i = 0; i<3; i++){ for (int j = 0; j<3; j++) cout << matrix[j][i] << " "; cout << endl; } system("pause"); return 0; }