언어/c언어

transpose matrix

파아랑새 2017. 10. 7. 10:07

# include <stdio.h>

# define SIZE 3

void TransPose(int[][SIZE]);

void ResultPrintf(int[][SIZE]);

int main(void) 

{

int mMat[SIZE][SIZE] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };

TransPose(mMat);

ResultPrintf(mMat);

return 0;

} // end of main function

void TransPose(int nParam[][SIZE])

{

int Telement = 0;

/*

1 2 3

4 5 6

7 8 9

*/

for (int R = 0; R < SIZE; R++)

{ // Row

for (int C = R; C < SIZE; C++)

{ // COL

Telement = nParam[R][C];

nParam[R][C] = nParam[C][R];

nParam[C][R] = Telement;

}

}

} // end of TransPose function

void ResultPrintf(int pMat[][SIZE])

{

for (int R = 0; R < SIZE; R++)

{

for (int C = 0; C < SIZE; C++)

{

printf("%d ", pMat[R][C]);

//printf("%d ", *((pMat + R) + C));

}

printf("\n");

}

} // end of ResultPrintf function