簡單一點的方法,直接設置兩個矩陣(100x100)然後交換就可以了。
#include <iostream>
using namespace std;
int main()
{
int row, column;
int matrixA[100][100] = {0}, matrixB[100][100] = {0};
while(cin>>row>>column)
{
//matrix init
for(int i = 0; i < row; ++i)
{
for(int j = 0; j < column; ++j)
{
cin>>matrixA[i][j];
}
}
//flip
for(int i = 0; i < row; ++i)
{
for(int j = 0; j < column; ++j)
{
matrixB[j][i] = matrixA[i][j];
}
}
//output
for(int i = 0; i < column; ++i)
{
for(int j = 0; j < row; ++j)
{
cout<matrixB[i][j];
if(j != row - 1 ) cout<<" ";
}
cout<endl;
}
}
return 0;
}