标签:cout print 获得 void mat temp use iostream using
//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("原矩阵:\n"); for (int i = 0; i<3; i++){ for (int j = 0; j<3; j++) cout << matrix[i][j] << " "; cout << endl; } printf("\n转置后矩阵:\n"); //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; }
标签:cout print 获得 void mat temp use iostream using
原文地址:https://www.cnblogs.com/277223178dudu/p/11371569.html