1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#include <iostream>
#define MAT_L 4
#define MAT_W 4
using namespace std;
void Transpose(int (*MAT_1)[MAT_W], int (*MAT_2)[MAT_W])
{
for(int R = 0; R < MAT_L; R++)
for(int C = 0; C < MAT_W; C++)
MAT_2[C][R] = MAT_1[R][C];
for(int C = 0; C < MAT_W; C++)
{
for(int R = 0; R < MAT_L; R++)
cout << MAT_2[C][R] << " ";
cout << endl;
}
}
int main()
{
int mat1[MAT_L][MAT_W] = { {1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12},
{13, 14, 15, 16}
};
int mat2[MAT_W][MAT_L] = { {0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0}
};
cout << "\nBefore transposing :-\n" << endl;
for(int R = 0; R < MAT_L; R++)
{
for(int C = 0; C < MAT_W; C++)
cout << mat1[R][C] << " ";
cout << endl;
}
cout << "\nAfter transposing matrix :-\n" << endl;
Transpose(mat1, mat2);
system("pause");
return 0;
}
|