Code:
#include <stdio.h>
void displayMatrix (int x, int y, int M3[x][y])
{
int a = 0, b = 0;
for ( a = 0; a <= x; ++a) {
for ( b = 0; b <= y; ++b)
printf("%5i", M3[a][b]);
printf("\n");
}
}
void transposeMatrix (int x, int y, int M1[x][y], int w, int z,int M2[w][z])
{
int a = 0, b = 0;
for ( a = 0; a <= x; ++a) {
for ( b = 0; b <= y; ++b)
M2[b][a] = M1[a][b];
}
}
int main (void)
{
void transposeMatrix (int x, int y, int M1[x][y], int w, int z,int M2[w][z]);
void displayMatrix (int x, int y, int M3[x][y]);
int Matrix2[5][4];
int Matrix1[4][5] =
{
{ 1, 2 , 3, 4, 5 },
{ 1, 2 , 3, 4, 5 },
{ 1, 2 , 3, 4, 5 },
{ 1, 2 , 3, 4, 5 }
};
displayMatrix(4, 5, Matrix1); //test display function -- seems to work yahoo..
printf("\n\n-----------------------------------\n\nTransposed matrix:\n\n"); // some space
transposeMatrix(4, 5, Matrix1, 5, 4, Matrix2);
displayMatrix(5, 4, Matrix2);
return 0;
}
I used void as return value for transposeMatrix cause I guess matrix behave like arrays, the matrix gets directly modified by the function? no need to return in theory? (even it might be good practice) Sorry for the maybe silly question but i just arrived to multi dimensional arrays and i can't quite figure it out myself.