네이버 ( 2018_10_07)
https://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040101&docId=311527705
# include <stdio.h>
# include <stdlib.h>
# define ERROR 1
// ==============================================
typedef struct mat {
int mat_one_3by4[3][4]; // 3by4 행렬
int mat_two_4by3[4][3]; // 4by3 행렬
int mat_mul_3by3[3][3]; // (3by4)x(4by3) - (3by3)
}mat;
// ==============================================
// 데이터 초기화
void _init_(mat** ppNode);
// 행렬 곱셈
void _multiplication_(mat** ppNode);
// 결과 출력
void _printfData_(mat** ppNode);
// ==============================================
int main(void) {
mat *ptr_node = NULL;
// [1] 동적 할당
ptr_node = (mat*)malloc(sizeof(mat));
if (ptr_node == NULL) {
printf("malloc fail !!!\n");
exit(ERROR);
}
else { // ptr_node != NULL
_init_(&ptr_node);
_multiplication_(&ptr_node);
_printfData_(&ptr_node);
}
// [1] 메모리 해제
free(ptr_node);
return 0;
} // end of main function
void _init_(mat** ppNode) {
int i, j; // index
int injection_data = 1;
// mat_one 셋팅)
for (i = 0; i < 3; i++) {
for (j = 0; j < 4; j++) {
(** ppNode).mat_one_3by4[i][j] = injection_data;
injection_data++; // 후위증감연산식
}
}
// mat_two 셋팅)
for (i = 0; i < 4; i++) {
for (j = 0; j < 3; j++) {
(** ppNode).mat_two_4by3[i][j] = injection_data;
injection_data++; // 후위증감연산식
}
}
// mat_mul 셋팅)
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
(** ppNode).mat_mul_3by3[i][j] = 0;
}
}
} // end of _init_ function
void _multiplication_(mat** ppNode) {
int i, j, k;
int temp;
for (k = 0; k < 3; k++) {
for (i = 0; i < 3; i++) {
temp = 0;
for (j = 0; j < 4; j++) {
temp += (** ppNode).mat_one_3by4[k][j] * (** ppNode).mat_two_4by3[j][i];
/*
01 02 03 04 13
05 06 07 08 16
09 10 11 12 19
22
*/
}
(** ppNode).mat_mul_3by3[k][i] = temp;
}
}
} // end of _multiplcation_ function
void _printfData_(mat** ppNode) {
int i, j;
printf("mat_one_3by3) \n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 4; j++) {
printf("%02d", (**ppNode).mat_one_3by4[i][j]);
if (j != 3) {
printf(" ");
}
}
printf("\n");
}
printf(" ==== x ==== \n");
printf("mat_two_4by3) \n");
for (i = 0; i < 4; i++) {
for (j = 0; j < 3; j++) {
printf("%02d", (**ppNode).mat_two_4by3[i][j]);
if (j != 3) {
printf(" ");
}
}
printf("\n");
}
printf(" = \n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
printf("%02d", (**ppNode).mat_mul_3by3[i][j]);
if (j != 3) {
printf(" ");
}
}
printf("\n");
}
} // end of _printfData_ function
'언어 > c언어' 카테고리의 다른 글
버블 (0) | 2018.10.08 |
---|---|
해공예 (0) | 2018.10.07 |
Naver_지식인 (0) | 2018.09.25 |
네이버 지식인 답변 (0) | 2018.09.14 |
http://www.jungol.co.kr/bbs/board.php?bo_table=pbank&wr_id=2069&sca=20 (0) | 2018.07.16 |