transpose matrix

언어/c언어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

'언어 > c언어' 카테고리의 다른 글

#네이버  (0) 2017.10.08
lotto 관련 코드 네이버 답변  (0) 2017.10.08
네이버 문제 풀이 ㅋㅋㅋ c언어 중간고사가 다가오나보군 ㅋㅋㅋ  (0) 2017.10.06
더블릿 koi_watch 문제  (0) 2017.10.05
원형 링크드  (0) 2017.10.05