https://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040101&docId=312059347&page=1#answer1

[code]

# include <stdio.h>

# include <stdlib.h>

# include <time.h>

# define AND &&

# define OR ||

# define ERROR 1

# define R 7

# define C 5

typedef struct MAT {

int Matrix[R][C]; // 6x4행렬

}MAT, *ptrMat;

// =====================================================================

void _init_(MAT** p);        // func(1) : 행렬 초기화 함수 

void rndValueInput(MAT** p); // func(2) : 랜덤으로 값 입력 최댓값 : 1000

void tempPrintf(MAT** p);    // func(3) : 전체 데이터 임시 출력

void resultPrintf(MAT** p);  // func(4) : 최종결과 출력

// =====================================================================

int main(void) {

// 

ptrMat pNode = NULL;

pNode = (ptrMat)malloc(sizeof(MAT)); // 동적 할당

if (pNode == NULL) {

printf("malloc fail !!!\n");

exit(ERROR);

}

else {

// pNode != NULL

_init_(&pNode);

rndValueInput(&pNode);

//tempPrintf(&pNode);

resultPrintf(&pNode);

}

free(pNode); // 메모리 해제 

return 0;

} // end of main function

// =====================================================================

// func(1)

void _init_(MAT** p) {

int i, j; // index

// 행_

for (i = 0; i < R; i++) {

// 열_

for (j = 0; j < C; j++) {

(** p).Matrix[i][j] = 0x0;

}

}

} // end of _init_ function

// =====================================================================

// func(2)

void rndValueInput(MAT** p) {

int i, j; // index

int row_temp;

int col_temp[4] = { 0, };

// seed 값

srand((unsigned)time(NULL)); 

// 행_

for (i = 0; i < R-1; i++) {

// 열_

row_temp = 0x0;

for (j = 0; j < C-1; j++) {

// 값 입력 범위 =  1 <= N <= 1000

(** p).Matrix[i][j] = rand() % 1000 + 1;

// 행에 대한 제어

row_temp += (** p).Matrix[i][j];

// 열에 대한 제어 

col_temp[j] += (** p).Matrix[i][j];

}

(** p).Matrix[i][C - 1] = row_temp;

}

// 데이터 적재 

for (j = 0; j < C - 1; j++) {

(** p).Matrix[R - 1][j] = col_temp[j];

}

} // end of rndValueInput function 

// =====================================================================

// func(3)

void tempPrintf(MAT** p) {

int i, j; // index

// 행_

for (i = 0; i < R; i++) {

// 열_

for (j = 0; j < C; j++) {

printf("%4d", (** p).Matrix[i][j]);

if (j != C - 1) {

printf("  ");

}

}

printf("\n"); // 개행

}

} // end of tempPrintf function 

// =====================================================================

// func(4)

void resultPrintf(MAT** p) {

int i, j; // index

// 행_

for (i = 0; i < R; i++) {

// 열_

for (j = 0; j < C; j++) {

if (i != R - 1 AND j != C - 1) {

printf("%6d", (** p).Matrix[i][j]);

}

else {

// j == C-1

if (i != R - 1 OR j != C - 1) {

printf("%.2lf", (double)((** p).Matrix[i][j]) / 4);

}

}

if (j != C - 1) {

printf("  ");

}

}

printf("\n"); // 개행

}

} // end of tempPrintf function 

[/code]

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

네이버 지식인 풀이  (0) 2018.11.07
네이버 지식인 풀이, c언어 숫자 거꾸로 출력  (0) 2018.11.03
네이버 지식인 풀이 링크드 리스트  (0) 2018.10.13
네이버 지식인 문제 풀이  (0) 2018.10.09
지식인 풀이  (0) 2018.10.09

https://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040101&docId=312021222

# include <stdio.h>

# include <stdlib.h>

# define ERROR 1

# define OR ||

// ===============================

typedef int element;


typedef struct ListNode {

element data;

struct ListNode* link;

}ListNode;


typedef struct ListLink {

ListNode *phead;

}ListLinkType;

// ===============================

void init(ListLinkType *param);                              // func (1)

ListNode* create_node(element data);                         // func (2)

void front_insert_node(ListLinkType* s, ListNode* new_node); // func (3)

void display(ListLinkType* s);                               // func (4)

void front_remove_node(ListLinkType* s);                     // func (5)

void concat(ListLinkType* s1, ListLinkType* s2);             // func (6)

ListNode* search(ListLinkType* s1, int x);                   // func (7)

// ===============================

int main(void) {

ListNode* new_node = NULL;

ListNode* p = NULL;

ListLinkType s1, s2;

init(&s1); // 초기화 1

init(&s2); // 초기화 2

// ==========================================

// 데이터 삽입 (10)

new_node = create_node(10); 

front_insert_node(&s1, new_node);

// 데이터 삽입 (20)

new_node = create_node(20);

front_insert_node(&s1, new_node);

// 데이터 삽입 (30)

new_node = create_node(30);

front_insert_node(&s1, new_node);

// ==========================================

// 데이터 출력

display(&s1);

// ==========================================

front_remove_node(&s1);

// 데이터 출력

printf("s1 node >>>   ");

display(&s1);


// 데이터 삽입 (40)

new_node = create_node(40);

front_insert_node(&s2, new_node);

// 데이터 삽입 (50)

new_node = create_node(50);

front_insert_node(&s2, new_node);

// 데이터 출력

printf("s2 node >>>   ");

display(&s2);


concat(&s1, &s2);

display(&s1);


p = search(&s1, 10);

if (p != NULL) {

printf("탐색 성공: %d \n", p->data);

else {

// p == NULL

printf("탐색 실패!!\n");

}

return 0;

} // end of main function 

void init(ListLinkType *param) {

param->phead = NULL;

} // end of init function 

// ===============================

ListNode* create_node(element data) {

ListNode* new_node = NULL;

new_node = (ListNode*)malloc(sizeof(ListNode));

if (new_node == NULL) {

printf("메모리 할당 에러 \n");

exit(ERROR);

}

else {

// new_node != NULL

new_node->data = data;

new_node->link = NULL;

}

return new_node;

} // end of create_node function 

// ===============================

void front_insert_node(ListLinkType* s, ListNode* new_node) {

if (s->phead == NULL) {

// 노드가 처음 추가되는 경우

s->phead = new_node;

}

else {

// s->phead != NULL

new_node->link = s->phead;

s->phead = new_node;

}

} // end of front_insert_node function 

// ===============================

void display(ListLinkType* s) {

ListNode *index = s->phead;

while (index != NULL) {

printf("%d", index->data);

if (index->link != NULL) {

printf("->");

}

index = index->link;

}

printf("\n\n");

} // end of display function 

// ===============================

void front_remove_node(ListLinkType* s) {

ListNode* removed = NULL;

if (s->phead == NULL) {

printf("삭제할 데이터가 없습니다!!! \n");

return;

}

else {

// s->phead != NULL

removed = s->phead;

s->phead = s->phead->link;

free(removed); // front node remove

}

} // end of front_remove_node function 

// ===============================

void concat(ListLinkType* s1, ListLinkType* s2) {

ListNode* p = s1->phead;

if (s1->phead == NULL OR s2->phead == NULL) {

return; // 종료

}

else {

// s1->phead != NULL AND s2->phead != NULL

while (1) {

if (p->link == NULL) {

break;

}

else {

p = p->link;

}

}

p->link = s2->phead;

}

} // end of concat function 

// ===============================

ListNode* search(ListLinkType* s1, int x) {

ListNode* p = s1->phead;

while (p != NULL) {

if (p->data == x) {

return p;

}

p = p->link;

}

return NULL; // 탐색 실패

} // end of search function 

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

네이버 지식인 풀이, c언어 숫자 거꾸로 출력  (0) 2018.11.03
네이버 지식인 풀이  (0) 2018.10.14
네이버 지식인 문제 풀이  (0) 2018.10.09
지식인 풀이  (0) 2018.10.09
행렬  (0) 2018.10.09

//=============================

# include <stdio.h>

# include <stdlib.h>

# include <time.h>

# include <stdbool.h>

# define ERROR 1

# define LEN 10

//=============================

typedef struct Num {

int element[LEN];

int min;

int max;

}Num, *ptrNum;

// FUNCTION PROTOTYPE ================================

void init(Num** param); // ======================= [1]

void randValueInput(Num** param); // ============= [2]

void minMax(Num** param); // ===================== [3]

// ===================================================

int main(void) {

ptrNum node = NULL;

node = (ptrNum)malloc(sizeof(Num));

if (node == NULL) {

printf("malloc fail ...!!!\n");

exit(ERROR);

}

init(&node);

randValueInput(&node);

minMax(&node);

free(node);

return 0;

} // end of main function

// ===================================================

void init(Num** param) { // ====================== [1]

int i; // index

for (i = 0; i < LEN; i++) {

(** param).element[i] = 0x0;

}

(** param).min = 0x0; // 최솟값

(** param).max = 0x0; // 최댓값

} // end of init function 

// ===================================================

void randValueInput(Num** param) { // ============ [2]

srand((unsigned)time(NULL));

int i; // index

for (i = 0; i < LEN; i++) {

(** param).element[i] = rand() % 20 + 1;

printf("%02d", (** param).element[i]);

if (i != LEN - 1) {

printf(" - ");

}

}

printf("\n\n");

} // end of randValueInput function

// ===================================================

void minMax(Num** param) { // ==================== [3]

int i, j; // index

bool flag;

int temp = 0x0;

for (i = 0; i < LEN - 1; i++) {

flag = false;

for (j = 0; j < LEN - 1; j++) {

if ((** param).element[j] > (** param).element[j + 1]) {

temp = (** param).element[j];

(** param).element[j] = (** param).element[j + 1];

(** param).element[j + 1] = temp;

flag = true;

}

}

if (flag == false) {

break;

}

}

// 최솟값

(** param).min = (** param).element[0];

// 최댓값

(** param).max = (** param).element[LEN - 1];

printf("최솟값 : %02d \n최댓값 : %02d \n", (** param).min, (** param).max);

} // end of minMax function 

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

네이버 지식인 풀이  (0) 2018.10.14
네이버 지식인 풀이 링크드 리스트  (0) 2018.10.13
지식인 풀이  (0) 2018.10.09
행렬  (0) 2018.10.09
버블  (0) 2018.10.08

지식인 풀이

언어/c언어2018. 10. 9. 17:30


# include <stdio.h>

# include <stdlib.h>

# include <stdbool.h>

# include <time.h>

# define NR 10  // ROW

# define NC 10  // COL

# define ERROR 1

# define SIZE 3

typedef struct MatOne {

/*

default  10 by 10 행렬

*/

int arr[NR][NC];

int row; // arrOne의 행

int col; // arrOne의 열

}MatInfo;


// function prototype -----------

void init(MatInfo** param);

void sizeRowCol(MatInfo** param);

void matValueInsert(MatInfo** param);

bool sizeCompare(MatInfo** M1, MatInfo** M2, MatInfo** M3);

void mulMatResult(MatInfo** M1, MatInfo** M2, MatInfo** M3);

void mulMatPrintf(MatInfo** M3);

void Tmatrix(MatInfo** M3);

// ------------------------------


int main(void) {

int i;

bool bValue = false;


MatInfo* matrix[3] = { 0, };

for (i = 0; i < 3; i++) {

matrix[i] = (MatInfo*)malloc(sizeof(MatInfo));

if (matrix[i] == NULL) {

printf("malloc error ... \n");

exit(ERROR);

}

else {

//matrix[i] != NULL

init(&matrix[i]);

if (i == 0 || i == 1) {

printf("%02d 번째 행렬 사이즈 조정\n", i + 1);

sizeRowCol((matrix + i));

matValueInsert((matrix + i));

printf("=====================\n");


}

}

}

bValue = sizeCompare(&matrix[0], &matrix[1], &matrix[2]);

if (bValue) {

printf("행렬 곱이 가능 합니다.\n");

mulMatResult(&matrix[0], &matrix[1], &matrix[2]);

printf("행렬 곱  ======================\n");

mulMatPrintf(&matrix[2]);

printf("==============================\n");


printf("전치행렬 ======================\n");

Tmatrix(&matrix[2]);

printf("==============================\n");

}

else {

printf("행렬 곱이 불가능 합니다.\n");

exit(ERROR);

}

for (i = 0; i < SIZE; i++) {

free(matrix[i]);

}

return 0;

}

// ------------------------------

void init(MatInfo** param) {

// 데이터 초기화 작업 

int i, j;

for (i = 0; i < NR; i++) {

for (j = 0; j < NC; j++) {

(**param).arr[i][j] = 0;

}

}

(**param).row = 0x0;

(**param).col = 0x0;

} // end of init function 


void sizeRowCol(MatInfo** param) {

while (1) {

// 행의 크기 입력

printf("row size input:  ");

scanf("%d", &(*param)->row);


// 열의 크기 입력

printf("column size input:  ");

scanf("%d", &(*param)->col);


if (((**param).row > 0 && (**param).row <= NR-1) &&

((**param).col > 0 && (**param).col <= NC-1)) {

printf("범위 성공!!! \n");

break;

}

else {

printf("plz  :  0 < N <= %d  \n",NR);

}

}

} // end of sizeRowCol function 


void matValueInsert(MatInfo** param) {

srand((unsigned)time(NULL));

int i, j;

// 랜덤으로 데이터 적재

for (i = 0; i < (**param).row; i++) {

for (j = 0; j < (**param).col; j++) {

(** param).arr[i][j] = rand() % 20 + 1;

// range :      1 <= N <= 20

}

}

// 데이터 출력

for (i = 0; i < (**param).row; i++) {

for (j = 0; j < (**param).col; j++) {

printf("%02d", (** param).arr[i][j]);

if (j != (**param).col - 1) {

printf(" ");

}

}

printf("\n");

}

} // end of matValueInsert function


bool sizeCompare(MatInfo** M1, MatInfo** M2, MatInfo** M3) {

/*

case 1)   A(2by4) x B(4by2)  = C(2by2)

case 2)   A(2by4) x B(3by2)  = 행렬 곱셈 불가

결론 : 앞행렬의 열과 뒤행렬의 행의 크기가 같아야 연산 가능

*/

if ((**M1).col == (**M2).row) {

(**M3).row = (**M1).row;

(**M3).col = (**M2).col;

return true;

}

else {

return false;

}

} // end of sizeCompare function 

void mulMatResult(MatInfo** M1, MatInfo** M2, MatInfo** M3) {

int i, j, k; // index

int temp;

for (i = 0; i < (**M1).row; i++) {

for (k = 0; k < (**M2).col; k++) {

temp = 0x0;

for (j = 0; j < (**M1).col; j++) {

temp += (**M1).arr[i][j] * (**M2).arr[j][k];

}

(**M3).arr[i][k] = temp;

}

}

} // end of matMatResult function 


void mulMatPrintf(MatInfo** M3) {

int i, j;

for (i = 0; i < (**M3).row; i++) {

// 행

for (j = 0; j < (**M3).col; j++) {

// 열

printf("%02d", (**M3).arr[i][j]);

if (j != (**M3).col - 1) {

printf(" ");

}

}

printf("\n");

}

} // end of matMatPrintf function 

    

void Tmatrix(MatInfo** M3) {

int Tmatrix[NR][NC] = { 0, };

int i, j; // index

for (i = 0; i < (** M3).col; i++) {

for (j = 0; j < (** M3).row; j++) {

Tmatrix[i][j] = (** M3).arr[j][i];

/*

    00 => 00

01 => 10

*/

printf("%02d", Tmatrix[i][j]);

if (j != (** M3).row - 1) {

printf(" ");

}

}

printf("\n");

}

} // end of Tmatrix function 

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

네이버 지식인 풀이 링크드 리스트  (0) 2018.10.13
네이버 지식인 문제 풀이  (0) 2018.10.09
행렬  (0) 2018.10.09
버블  (0) 2018.10.08
해공예  (0) 2018.10.07

행렬

언어/c언어2018. 10. 9. 08:56

# include <stdio.h>

typedef struct Matrix {

int MatOne[2][3];    // 2by3

int MatTwo[3][4];    // 3by4

int mulMat[2][4];    // 2by4

}Matrix;

// function type --------------------

void _init_(Matrix* nParam);

void _matValue_(Matrix* nParam);

void _matrixMul_(Matrix* nParam);

void _printfData_(Matrix* nParam);

// ----------------------------------

int main(void) {

Matrix node;

_init_(&node);

_matValue_(&node);

_matrixMul_(&node);

_printfData_(&node);

return 0;

} // end of main function

void _init_(Matrix* nParam) {

int i, j; // index

// 2by3

for (i = 0; i < 2; i++) {

for (j = 0; j < 3; j++) {

(*nParam).MatOne[i][j] = 0;

}

}


// 3by4

for (i = 0; i < 3; i++) {

for (j = 0; j < 4; j++) {

(*nParam).MatTwo[i][j] = 0;

}

}


// 2by4

for (i = 0; i < 2; i++) {

for (j = 0; j < 4; j++) {

(*nParam).mulMat[i][j] = 0;

}

}

} // end of _init_ function


void _matValue_(Matrix* nParam) {

srand((unsigned)time(NULL));

int i, j; // index

// 2by3

for (i = 0; i < 2; i++) {

for (j = 0; j < 3; j++) {

(*nParam).MatOne[i][j] = rand() % 50 + 1;

}

}


// 3by4

for (i = 0; i < 3; i++) {

for (j = 0; j < 4; j++) {

(*nParam).MatTwo[i][j] = rand() % 50 + 1;

}

}

} // end of _matValue_ function 


void _matrixMul_(Matrix* nParam) {

int i, j, k;

int temp;

for (i = 0; i < 2; i++) {

for (k = 0; k < 4; k++) {

temp = 0x0;

for (j = 0; j < 3; j++) {

temp = temp + (*nParam).MatOne[i][j] * (*nParam).MatTwo[j][k];

}

(*nParam).mulMat[i][k] = temp;

}

}

} // end of _matrixMul_ function

void _printfData_(Matrix* nParam) {

int i, j;

for (i = 0; i < 2; i++) {

for (j = 0; j < 4; j++) {

printf("%02d", (*nParam).mulMat[i][j]);

if (j != 3) {

printf("  ");

}

}

printf("\n");

}

} // end of _printfData_ function 

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

네이버 지식인 문제 풀이  (0) 2018.10.09
지식인 풀이  (0) 2018.10.09
버블  (0) 2018.10.08
해공예  (0) 2018.10.07
네이버 ( 2018_10_07)  (0) 2018.10.07

버블

언어/c언어2018. 10. 8. 23:10

# include <stdio.h>

# include <stdlib.h>

# include <time.h>

# define LEN 6

typedef struct nData {

int x[LEN];

}nData, *pNdata;

//========================================

void _init_(nData** nparam);

void _bubbleSort_(nData** nparam);

void _last_(nData** nparam);

//========================================

int main(void) {

srand((unsigned)time(NULL));

pNdata node = NULL;

node = (pNdata)malloc(sizeof(nData));

_init_(&node);

_bubbleSort_(&node);

_last_(&node);

free(node);

return 0;

} // end of main function 

//========================================

void _init_(nData** nparam) {

int i; 

printf("초기값 : ");

for (i = 0; i < LEN; i++) {

*((*nparam)->x + i) = rand() % 100 + 1;

printf("%2d", *((*nparam)->x + i));

if (i != LEN - 1) {

printf(" ");

}

}

printf("\n");

} // end of _init_ function

//========================================

void _bubbleSort_(nData** nparam) {

int i, j, k;

int temp = 0;

for (i = 1; i <= LEN-1; i++) {

printf("%2d단계 : ", i);

for (j = 0; j < LEN-1; j++) {

if ((** nparam).x[j] > (** nparam).x[j + 1]) {

temp = (** nparam).x[j];

(** nparam).x[j] = (** nparam).x[j + 1];

(** nparam).x[j + 1] = temp;

}

}

for (k = 0; k < LEN; k++) {

printf("%2d", *((*nparam)->x + k));

if (k != LEN - 1) {

printf(" ");

}

}

printf("\n");

}

} // end of _bubbleSort_ function

void _last_(nData** nparam) {

int i;

printf("정렬결과 : ");

for (i = 0; i < LEN; i++) {

printf("%2d", *((*nparam)->x + i));

if (i != LEN - 1) {

printf(" ");

}

}

printf("\n");

} // end of _last_ function 



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

지식인 풀이  (0) 2018.10.09
행렬  (0) 2018.10.09
해공예  (0) 2018.10.07
네이버 ( 2018_10_07)  (0) 2018.10.07
Naver_지식인  (0) 2018.09.25

해공예

언어/c언어2018. 10. 7. 12:15

# include <stdio.h>

# include <string.h>

# include <stdlib.h>

# define LEN 30

# define ERROR 1

typedef struct Q {

char sData[LEN];

}Q;

// 함수 원형_________________

// [1]

void _init_(Q**);

// [2]

void _TEXTwrite_(Q**);

// [3]

void _PrintfData_(Q**);

// _________________________

int main(void) {

Q* stu = NULL;

stu = (Q*)malloc(sizeof(Q));

if (stu == NULL) {

printf("malloc fail ...!!\n");

exit(ERROR);

}

else {

// stu != NULL

_init_(&stu);

_TEXTwrite_(&stu);

_PrintfData_(&stu);

}

free(stu);

return 0;

}


// [1]

void _init_(Q** nParam) {

strcpy((**nParam).sData, "\0");

} // end of _init_ function


// [2]

void _TEXTwrite_(Q** nParam) {

puts("입력:  ");

fgets((**nParam).sData, LEN, stdin);

(**nParam).sData[strlen((**nParam).sData) - 1] = '\0';

} // end of _TEXTwrite_ function 


// [3]

void _PrintfData_(Q** nParam) {

int i, j, k, x; // index

for (i = strlen((**nParam).sData) - 1; i >= 0; i--) {

// 공백

/*

ex) abc 

++c

+bcb

abcba

*/

for (x = 0; x < i; x++) {

printf(" ");

}

// 역방향

for (k = i; k <= strlen((**nParam).sData) - 2; k++) {

printf("%c", (**nParam).sData[k]);

}

// 정방향

for (j = strlen((**nParam).sData) - 1; j >= i; j--) {

printf("%c", (**nParam).sData[j]);

printf("\n"); // 개행

}

} // end of _PrintfData_ function 


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

행렬  (0) 2018.10.09
버블  (0) 2018.10.08
네이버 ( 2018_10_07)  (0) 2018.10.07
Naver_지식인  (0) 2018.09.25
네이버 지식인 답변  (0) 2018.09.14

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

Naver_지식인

언어/c언어2018. 9. 25. 22:15


https://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040101&docId=310710679

# include <stdio.h>

# include <string.h>

# include <stdlib.h>

# define SIZE 10

typedef struct Calc {

char opOne[SIZE];

char ope;

char opTwo[SIZE];

char resultv[SIZE*2];

int resultInt;

}Calc;

// ==========================================

//1.

void _init_(Calc* nParam);

//2.

void _valueInput_(Calc* nParam);

//3.

void _result_(Calc* nParam);

// ==========================================

int main(void) {

Calc myNode;

_init_(&myNode);

_valueInput_(&myNode);

_result_(&myNode);

printf("Result: %d\n", myNode.resultInt);

return 0;

} // end of main function 

// ==========================================

void _init_(Calc* nParam) {

nParam->ope = '\0';

strcpy(nParam->opOne, "\0");   // 숫자 _01

strcpy(nParam->opTwo, "\0");   // 숫자 _02

strcpy(nParam->resultv, "\0"); // 연산자 

nParam->resultInt = 0x0;

} // end of _init_ function

// ==========================================

void _valueInput_(Calc* nParam) {

printf("OP#1: ");

gets(nParam->opOne);

printf("OPER: ");

scanf("%c", &nParam->ope);

rewind(stdin); // 버퍼 비우기 

printf("OP#2: ");

gets(nParam->opTwo);

}

// ==========================================

void _result_(Calc* nParam) {

switch (nParam->ope) {

case '@':

strcpy(nParam->resultv, nParam->opOne);

strcat(nParam->resultv, nParam->opTwo);

nParam->resultInt = atoi(nParam->resultv);

nParam->resultInt += 1;

break;

case '#':

strcpy(nParam->resultv, nParam->opTwo);

strcat(nParam->resultv, nParam->opOne);

nParam->resultInt = atoi(nParam->resultv);

nParam->resultInt -= 1;

break;

default:

printf("error ... !!!\n");

exit(1);

}

}



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

해공예  (0) 2018.10.07
네이버 ( 2018_10_07)  (0) 2018.10.07
네이버 지식인 답변  (0) 2018.09.14
http://www.jungol.co.kr/bbs/board.php?bo_table=pbank&wr_id=2069&sca=20  (0) 2018.07.16
네이버 지식인 문제 풀이  (0) 2018.06.15

네이버 지식인 답변

https://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040101&docId=309943939

# include <stdio.h>

# include <stdlib.h>

typedef struct Matrix {

int mat_one[2][4];

int mat_two[4][2];

int result_mat[2][2];

}Matrix, *ptr_Matrix;

// function prototype ==========================

void __init__(Matrix ** m);

void __matSetting__(Matrix ** m);

void __matMul__(Matrix ** m);

void __result__(Matrix ** m);

// =============================================

int main(void) {

ptr_Matrix my = NULL;

// 메모리 동적 할당

my = (ptr_Matrix)malloc(sizeof(Matrix));


if (my == NULL) {

exit(1);

}

else {

__init__(&my);

__matSetting__(&my);

__matMul__(&my);

__result__(&my);

}

// 메모리 해제

free(my);

return 0;

} // end of main function 


// =============================================

void __init__(Matrix ** m) {

int i, j;

// mat_one 행렬 초기화

for (i = 0; i < 2; i++) {

for (j = 0; j < 4; j++) {

*(*((*m)->mat_one + i) + j) = 0;

}

}


// mat_two 행렬 초기화

for (i = 0; i < 4; i++) {

for (j = 0; j < 2; j++) {

*(*((*m)->mat_two + i) + j) = 0;

}

}


// result 행렬 초기화

for (i = 0; i < 2; i++) {

for (j = 0; j < 2; j++) {

*(*((*m)->result_mat + i) + j) = 0;

}

}

} // end of __init__ function 


// =============================================

void __matSetting__(Matrix ** m) {

int i, j; // index

int num = 1;

// mat_one 행렬 초기화

for (i = 0; i < 2; i++) {

for (j = 0; j < 4; j++) {

*(*((*m)->mat_one + i) + j) = num;

++num;

}

}

// mat_two 행렬 초기화

for (i = 0; i < 4; i++) {

for (j = 0; j < 2; j++) {

*(*((*m)->mat_two + i) + j) = num;

++num;

}

}

} // end of __matSetting__ function 


void __matMul__(Matrix ** m) {

int i, j, k;


for (i = 0; i < 2; i++) {

for (j = 0; j < 2; j++) {

int tmp_number = 0x0;

for (k = 0; k < 4; k++) {

// (2by4) x (4by2) = (2by2)

tmp_number += ((**m).mat_one[i][k] * (**m).mat_two[k][j]);

/*

00     00

01     10

*/

}

(**m).result_mat[i][j] = tmp_number;

}

}

} // end of __matMul__ function

void __result__(Matrix ** m) {

int i, j;

for (i = 0; i < 2; i++) {

for (j = 0; j < 2; j++) {

printf("%d", (**m).result_mat[i][j]);

if (j != 2) {

printf(" ");

}

}

printf("\n");

}

}

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

네이버 ( 2018_10_07)  (0) 2018.10.07
Naver_지식인  (0) 2018.09.25
http://www.jungol.co.kr/bbs/board.php?bo_table=pbank&wr_id=2069&sca=20  (0) 2018.07.16
네이버 지식인 문제 풀이  (0) 2018.06.15
네이버 지식인 문제 _02  (0) 2018.06.12