http://59.23.150.58/30stair/pie/pie.php?pname=pie&stair=3


# include <stdio.h>

# include <stdlib.h>

# define AND &&

typedef struct {

int Fone[2];  // 0: 분자 , 1: 분모

int Ftwo[2];  // 0: 분자 , 1: 분모

int result[2];// 0: 분자 , 1: 분모

}Friends, *ptrFriends;

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

ptrFriends retNode();        // func (0)

void _init_(Friends** p);    // func (1)

void WriteData(Friends** p); // func (2)

void step01(Friends** p);    // func (3)

void result(Friends** p);    // func (4)

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

int main(void) { //   [MAIN FUNCTION] 

ptrFriends node = NULL;

node = retNode();

_init_(&node); // 초기화

WriteData(&node);

step01(&node);

result(&node);

return 0;

} // end of main function

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

ptrFriends retNode() {       // func (0)

ptrFriends ret_ = NULL;

ret_ = (ptrFriends)malloc(sizeof(Friends));

return ret_;

} // end of retNode function 

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

void _init_(Friends** p) {   //  func (1)

int i; // index

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

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

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

} // endfor

} // end of _init_ function 

void WriteData(Friends** p) { // func (2)

int i;

scanf("%d %d", &(**p).Fone[0], &(**p).Fone[1]);  

scanf("%d %d", &(**p).Ftwo[0], &(**p).Ftwo[1]); 

} // end of WriteData function 

void step01(Friends** p) {   //  func (3)

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

int tmp = 0x0;

int i; // index

int divisor = 0x0;

int large; // 큰 수 

int small; // 작은 수 

int t1, t2, t3;

int tempOne;

int tempTWO;

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

if((*p)->Fone[1] != (*p)->Ftwo[1]) { // 분모가 서로 다른 경우 통분

// (*p)->Fone[1] != (*p)->Ftwo[1]

// 통분

large = (*p)->Fone[1];

small = (*p)->Ftwo[1];


if (large < small) {

tmp = large;

large = small;

small = tmp;

}


for (i = 1; i <= small; i++) {

if (small%i == 0 AND large%i == 0) {

divisor = i;

}

} // endfor

tempOne = (*p)->Ftwo[1];

tempTWO = (*p)->Fone[1];

if (divisor == 1) { // case 1) 서로소 인 관계

// one

(*p)->Fone[1] = (*p)->Fone[1] * tempOne; // 분모

(*p)->Fone[0] = (*p)->Fone[0] * tempOne; // 분자

// two

(*p)->Ftwo[1] = (*p)->Ftwo[1] * tempTWO; // 분모

(*p)->Ftwo[0] = (*p)->Ftwo[0] * tempTWO; // 분자

}

else { // case 2) 서로소가 아닌 관계

t1 = ((*p)->Fone[1] * (*p)->Ftwo[1]) / divisor;

t2 = t1 / (*p)->Fone[1];

t3 = t1 / (*p)->Ftwo[1];

// one 

(*p)->Fone[1] = t1;// 분모

(*p)->Fone[0] = (*p)->Fone[0] * t2; // 분자


// two

(*p)->Ftwo[1] = t1;// 분모

(*p)->Ftwo[0] = (*p)->Ftwo[0] * t3; // 분자

}

tmp = ((*p)->Fone[1] - ((*p)->Fone[0] + (*p)->Ftwo[0]));

if (tmp == 0) { // 다 먹은 경우

// case 1-1)

(*p)->result[0] = 0;

(*p)->result[1] = 0;

}

else {  // 일부 남게 되는 경우

// case 1-2) 

if ((*p)->Fone[1] % tmp == 0) { 

// case 1-2-1) 분모가 분자로 나누어 떨어지는 경우

(*p)->result[0] = 1;

(*p)->result[1] = (int)((*p)->Fone[1] / tmp);

else { 

// case 1-2-2) 분모가 분자로 나누어 떨어지지 않는 경우

//(*p)->Fone[1] % tmp != 0

for (i = 1; i < tmp; i++) {

if (tmp%i == 0 AND(*p)->Fone[1] % i == 0) {

divisor = i;

}

}

if (divisor == 1) {

(*p)->result[0] = tmp;           // 분자

(*p)->result[1] = (*p)->Fone[1]; // 분모

}

else {

// divisor != 1

(*p)->result[0] = tmp/divisor;             // 분자

(*p)->result[1] = (*p)->Fone[1] / divisor; // 분모

}

}

}

} // end of step01 function  

void result(Friends** p) { //  func (4)

if ((*p)->result[0] == 0) {

printf("%d\n", 0);

}

else {

// (*p)->result[0] != 0

printf("%d/%d\n", (*p)->result[0], (*p)->result[1]);

}

} // end of result function 

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

네이버 지식인 풀이  (0) 2018.11.22
네이버 풀이  (0) 2018.11.19
선택정렬  (0) 2018.11.18
버블 정렬  (0) 2018.11.18
c언어 네이버 지식인 풀이  (0) 2018.11.17

선택정렬

언어/c언어2018. 11. 18. 12:53

# include <stdio.h>

# include <time.h>

# define LEN 10

typedef struct 

{

int arry[LEN];

}STU;

// FUNCTION PROTOTYPE -----------

void _init_(STU* p);     // func (1)

void dataSetting(STU* p); //func (2)

void selectSort(STU* p); // func (3)

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

int main(void)

{

STU node;

_init_(&node);

dataSetting(&node);

selectSort(&node);

return 0;

} // end of main function

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

void _init_(STU* p)     // func (1)

{

int i; // index

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

{

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

} // endfor

} // end of _init_ function 

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

void dataSetting(STU* p) // func (2)

{

srand((unsigned)time(NULL));

int i; // index

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

{

(*p).arry[i] = rand() % 30 + 1;

printf("[%2d]", (*p).arry[i]);

if (i != LEN - 1)

{

printf(" => ");

}

}

printf("\n");

} // end of dataSetting function 

void selectSort(STU* p) // func (1)

{

int i, j, k; // index

int tmp;

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

{

for (j = i + 1; j < LEN; j++)

{

if ((*p).arry[i] > (*p).arry[j])

{

tmp = (*p).arry[i];

(*p).arry[i] = (*p).arry[j];

(*p).arry[j] = tmp;


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

{

printf("[%2d]", (*p).arry[k]);

if (k != LEN - 1)

{

printf(" => ");

} // endif

} // endfor

printf("\n");

} // endif

} // endfor

} // endfor

} // end of selectSort function 

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

네이버 풀이  (0) 2018.11.19
더블릿 풀이 c언어 pie 문제  (0) 2018.11.18
버블 정렬  (0) 2018.11.18
c언어 네이버 지식인 풀이  (0) 2018.11.17
네이버 지식인 풀이  (0) 2018.11.14

버블 정렬

언어/c언어2018. 11. 18. 12:53


// bubble 정렬

# include <stdio.h>

# include <stdlib.h>

# include <stdbool.h>

# include <time.h>

# define LENGH 10

typedef struct {

int arr[LENGH];

}bubble;

// 함수 원형 ________________

void _init_(bubble* p);        // func (1)

void _valueInsert_(bubble* p); // func (2)

void _bubbleSort_(bubble* p);  // func (3)

// _________________________

int main(void) { // main function 

bubble sNode;

// 데이터 초기화

_init_(&sNode);

_valueInsert_(&sNode);

_bubbleSort_(&sNode);

return 0;

} // end of main function

// _________________________

void _init_(bubble* p) { // func (1)

int i; // index

for (i = 0; i < LENGH; i++)

p->arr[i] = 0x0;

} // end of _init_ function

// _________________________

void _valueInsert_(bubble* p) { // func (2)

int i; // index

srand((unsigned)time(NULL));

for (i = 0; i < LENGH; i++)

p->arr[i] = rand() % 20 + 1;


// check

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

printf("%d", p->arr[i]);

if (i != LENGH - 1) {

printf("=>");

}

}

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

} // end of _valueInsert_ function

// _________________________

void _bubbleSort_(bubble* p) { // func (3)

int i, j, k;

int temp = 0x0;

int num = 0x1;

bool flag;

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

flag = true;

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

if (p->arr[j] > p->arr[j + 1]) {

flag = false;

temp = p->arr[j];

p->arr[j] = p->arr[j + 1];

p->arr[j + 1] = temp;

printf("[%02d] :  ", num);

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

printf("[%02d]", p->arr[k]);

if (k != LENGH - 1) {

printf("=>");

}

else {

printf("\n");

}

}

++num;

}

} // endfor

if (flag) {

break;

}

} // endfor

} // end of _bubbleSort_ function 

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

더블릿 풀이 c언어 pie 문제  (0) 2018.11.18
선택정렬  (0) 2018.11.18
c언어 네이버 지식인 풀이  (0) 2018.11.17
네이버 지식인 풀이  (0) 2018.11.14
네이버 지식인 답변  (0) 2018.11.12

https://kin.naver.com/qna/detail.nhn?d1id=11&dirId=1113&docId=314491480

/*


작성자 : sleep4725


윈도우 10 환경


visual studio 2013


*/

# include <stdio.h>

# include <stdlib.h>

# include <string.h>

# define _CRT_SECURE_NO_WARNINGS

# define LEN 20

typedef struct {

char idNumber[LEN]; // 번호

char stuName[LEN]; // 학생이름

int kor; //  국어

int eng; //  영어

int math; // 수학

int tot; // 총점

double avg; // 평균

}STU, *pSTU;

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

pSTU retNode(int); //                  func (1)

void stuInfoSetting(STU**, int*); //   func (2)

void bubbleSort(STU**, int*); //       func (3)

void sortPrintf(STU**, int*); //       func (4)

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

int main(void) { //                main function 

pSTU stuInfor = NULL;

unsigned int stuCount = 0x0;

printf("성적을 처리할 학생들은 몇 명 입니까? ");

scanf("%d", &stuCount);

stuInfor = retNode(stuCount);

if (stuInfor == NULL) {

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

exit(1);

}

stuInfoSetting(&stuInfor, &stuCount);

//bubbleSort(&stuInfor, &stuCount);

sortPrintf(&stuInfor, &stuCount);

return 0;


} // end of main function

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

pSTU retNode(int cnt) { // func (1)

pSTU tmp = NULL;

tmp = (pSTU)malloc(sizeof(STU)*cnt);

return tmp;

} // end of retNode function 

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

void stuInfoSetting(STU** pNode, int* cnt) { // func (2)

int i; // index

for (i = 0; i < *cnt; i++) {

// 학생 이름 입력 : string

printf("학생 이름 입력:  ");

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

gets((*pNode + i)->stuName); // gets_s 함수는 비표준 


// 학생 학번 입력 : string

printf("학생 학번 입력:  ");

gets((*pNode + i)->idNumber);


// 국어 점수 입력 : int

printf("국어 점수 입력:  ");

scanf("%d", &(*pNode + i)->kor);

// 영어 점수 입력 : int

printf("영어 점수 입력:  ");

scanf("%d", &(*pNode + i)->eng);

// 수학 점수 입력 : int

printf("수학 점수 입력:  ");

scanf("%d", &(*pNode + i)->math);

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

// 총점 

(*pNode + i)->tot = (*pNode + i)->kor + (*pNode + i)->eng + (*pNode + i)->math;

(*pNode + i)->avg = (double)(** pNode).tot / 3;

} // endfor

} // end of stuInfoSetting function 

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

void bubbleSort(STU** pNode, int* cnt) { // func (3)

int i, j; // index

STU swapNode;

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

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

// 총점을 기준으로 오름차순 정렬

if ((*pNode)[j].tot > (*pNode)[j + 1].tot) {

memcpy(&swapNode, &(*pNode)[j], sizeof(STU));

memcpy(&(*pNode)[j], &(*pNode)[j + 1], sizeof(STU));

memcpy(&(*pNode)[j + 1], &swapNode, sizeof(STU));

}

} // endfor

} // endfor

} // end of bubbleSort function 

void sortPrintf(STU** pNode, int* cnt) { // func (4)

int i; // index

for (i = 0; i < (*cnt); i++) {

printf("학번 :  %s\n", (*pNode)[i].idNumber);

printf("이름 :  %s\n", (*pNode)[i].stuName);

printf("국어 :  %d\n", (*pNode)[i].kor);

printf("영어 :  %d\n", (*pNode)[i].eng);

printf("수학 :  %d\n", (*pNode)[i].math);

printf("총점 :  %d\n", (*pNode)[i].tot);

printf("평균 :  %0.2lf\n", (*pNode)[i].avg);

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

}

} // end of sortPrintf function 

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

선택정렬  (0) 2018.11.18
버블 정렬  (0) 2018.11.18
네이버 지식인 풀이  (0) 2018.11.14
네이버 지식인 답변  (0) 2018.11.12
네이버 지식인 풀이  (0) 2018.11.10

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

# include <stdio.h>

# include <stdlib.h>

# include <stdbool.h>

# define _CRT_SECURE_NO_WARNINGS


typedef struct {

unsigned int height;

unsigned int choice;

}STAR, *ptrSTAR;

// 함수 원형_________________________________

void _init_(STAR** param); //   func (1)

void _choice_(STAR** param); // func (2)

void _one_(STAR** param); //    func (3)

void _two_(STAR** param); //    func (4)

void _three_(STAR** param); //  func (5)

// _________________________________________

int main(void) {

ptrSTAR node = NULL;

node = (ptrSTAR)malloc(sizeof(STAR));

if (node == NULL) {

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

exit(1);

}

// node != NULL

_init_(&node);

_choice_(&node);

// 동적할당 해제

free(node);

return 0;

} // end of main function 

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

void _init_(STAR** param) { // func (1)

(** param).height = 0x0;

while (true) {

printf("높이 입력해줘:  ");

scanf("%d", &(** param).height);


if ((** param).height % 2 == 0) {

printf("높이는 반드시 홀수여야 합니다.\n");

}

else { // 높이 값이 홀수 인 경우

break;

}

}

} // end of _init_ function 

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

void _choice_(STAR** param) { // func (2)

while (true) {

printf("1,2,3 중 한개 선택: ");

scanf("%d", &(** param).choice);


if (1 <= (** param).choice && (** param).choice <= 3) {

break;

}

else {

printf("잘못 입력하셨습니다. \n");

}

}

switch ((**param).choice) {

case 1:

_one_(param);

break;

case 2:

_two_(param);

break;

case 3:

_three_(param);

break;

}


} // end of _choice_ function

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

void _one_(STAR** param) { // func (3)

/*

ex)


   *****

    ***

     *

*/

unsigned int i, j, k;

// 높이

for (i = (** param).height; i >= 1; i--) { 

// 공백

for (j = i; j < (**param).height; j++) {

printf(" ");

} // end 

// 별

for (k = 2*i-1; k >=1 ; k--) {

printf("*");

} // end for2

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

} // 

} // end of _one_ function 

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

void _two_(STAR** param) { // func (4)

/*

ex)


       *

      ***

     *****

      ***

       *

*/

unsigned int i, j, k;

// 상단

for (i = 1; i <= (**param).height; i++) {

// 공백

for (j = i; j < (**param).height; j++) {

printf(" ");

} // end 

  // 별

for (k = 1; k <= 2 * i - 1; k++) {

printf("*");

} // end for2

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

if (i == (**param).height) {

// 하단

for (i = (**param).height - 1; i >= 1; i--) {

// 공백

for (j = i; j <= (**param).height-1; j++) {

printf(" ");

} // endfor

// 별

for (k = 2 * i - 1; k >= 1; k--) {

printf("*");

} // endfor

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

} // endfor

i = (**param).height;

} // endif

} // 

} // end of _two_ function

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

void _three_(STAR** param) { // func (5)

/*

ex)


     *****  

      ***

       *

      ***

     *****

*/


unsigned int i, j, k;

// 상단

for (i = (**param).height; i >= 1;  i--) {

// 공백

for (j = i; j < (**param).height; j++) {

printf(" ");

} // end 

// 별

for (k = 2 * i - 1; k >= 1; k--) {

printf("*");

} // end for2

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

if (i == 1) {

// 하단

for (i = 1; i <= (**param).height - 1; i++) {

// 공백

for (j = i; j < (**param).height - 1; j++) {

printf(" ");

} // endfor

// 별

for (k = 1; k <= 2 * i + 1; k++) {

printf("*");

} // endfor

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

} // endfor

i = 1;

} // endif

} // 

} // end of _three_ function 

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

버블 정렬  (0) 2018.11.18
c언어 네이버 지식인 풀이  (0) 2018.11.17
네이버 지식인 답변  (0) 2018.11.12
네이버 지식인 풀이  (0) 2018.11.10
네이버 풀이  (0) 2018.11.10

# include <stdio.h>


typedef struct {

int left_x;

int left_y;

int right_x;

int right_y;

}RECT;

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

void _init_(RECT*);      // func (1)

void insert(RECT*);      // func (2)

void temp_coordi(RECT*); // func (3)

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

int main(void) { 

RECT rect_node;

_init_(&rect_node);

insert(&rect_node);

temp_coordi(&rect_node);

return 0;

} // end of main function

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

void _init_(RECT* param) { // func (1)

// 데이터 초기화

// 좌상단

param->left_x = 0x0;

param->left_y = 0x0;

// 우하단

param->right_x = 0x0;

param->right_y = 0x0;

} // end of _init_ function 

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

void insert(RECT* param) { // func (2)

int temp_x = 0x0;

int temp_y = 0x0;

int flag = 0x0;

printf("좌상단점/우하단점의 좌표를 입력하세요(left, top, right, bottom 순)\n");

scanf("%d %d %d %d", 

&param->left_x, &param->left_y,

&param->right_x, &param->right_y);

printf("입력된 직사각형: 좌상단점=(%d,%d), 우하단점=(%d,%d)\n", 

param->left_x, param->left_y, param->right_x, param->right_y);

while (1) {

if (param->left_x < param->right_x) {

if (param->left_y < param->right_y) {

break;

}

else if (param->left_y > param->right_y) {

// case1-2) 좌상단의 x좌표가 우하단의 x좌표보다 작고

// 좌상단의 y좌표가 우상단의 y좌표보다 큰 경우 

// y좌표를 서로 교체

temp_y = param->left_y;

param->left_y = param->right_y;

param->right_y = temp_y;

flag = 1;

break;

}

else {

// case1-3) 좌상단의 y좌표와 우하단의 y좌표가 서로 같은 경우

printf("사각형 영역을 형성할 수 없습니다.\n");

}

}

else if (param->left_x > param->right_x) {

// 좌상단의 x값이 우하단의 x값보다 더 큰 경우

if (param->left_y < param->right_y) {

// 좌상단의 y값이 우하단의 y값보다 더 작은 경우

// x값을 서로 교체

temp_x = param->left_x;

param->left_x = param->right_x;

param->right_x = temp_x;

flag = 1;

break;

}

else if (param->left_y > param->right_y) {

// 좌상단의 y값이 우하단의 y값보다 더 큰 경우

// 좌상단과 우하단의 좌표를 서로 교체

temp_x = param->left_x;

temp_y = param->left_y;

param->left_x = param->right_x;

param->left_y = param->right_y;

param->right_x = temp_x;

param->right_y = temp_y;

flag = 1;

break;

}

else { // param->left_y == param->right_y

printf("사각형 영역을 형성할 수 없습니다.\n");

}

}

else { // param->left_x == param->right_x

printf("사각형 영역을 형성할 수 없습니다.\n");

}

}

if (flag) {

printf("수정된 직사각형: 좌상단점=(%d,%d), 우하단점=(%d,%d)\n",

param->left_x, param->left_y, param->right_x, param->right_y);

}

} // end of insert function 

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

void temp_coordi(RECT* param) { // func (3)

int temp_x = 0; 

int temp_y = 0;

printf("한점의 좌표를 입력하세요(x, y) : ");

scanf("%d %d", &temp_x, &temp_y);


if (param->left_x <= temp_x && param->right_x >= temp_x) {

if (param->left_y <= temp_y && param->right_y >= temp_y) {

printf("(%d, %d)는 직사각형 내부에 있습니다. \n", temp_x, temp_y);

}

else {

printf("(%d, %d)는 직사각형 내부에 없습니다. \n", temp_x, temp_y);

}

}

else {

printf("(%d, %d)는 직사각형 내부에 없습니다. \n", temp_x, temp_y);

}

} // end of temp_coordi function 

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

c언어 네이버 지식인 풀이  (0) 2018.11.17
네이버 지식인 풀이  (0) 2018.11.14
네이버 지식인 풀이  (0) 2018.11.10
네이버 풀이  (0) 2018.11.10
네이버 지식인 풀이  (0) 2018.11.07

# include <stdio.h>

# include <stdlib.h>

# include <time.h>

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

typedef struct {

int** Mat;

int size; // 행렬의 크기

int sum; // 행과열의 합

}Matrix;

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

void size_setting(Matrix**);     // func (1)

void element_insert(Matrix**);   // func (2)

void row_col_totalSum(Matrix**); // func (3)

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

int main(void) {

Matrix* pMat = NULL;

pMat = (Matrix*)malloc(sizeof(Matrix)); // 메모리 할당

if (pMat == NULL) {

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

exit(1);

}

size_setting(&pMat);

element_insert(&pMat);

row_col_totalSum(&pMat);

// 메모리 해제

free(pMat);

return 0;

} // end of main function 

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

void size_setting(Matrix** p) { // func (1)

int i, j; // index

printf("행렬 크기 입력:  ");

scanf("%d", &(**p).size);

(*p)->Mat = (int**)malloc(sizeof(int*)*(**p).size);

for (i = 0; i < (**p).size; i++) {

*((*p)->Mat + i) = (int*)malloc(sizeof(int)*(**p).size);

}

// 배열 초기화

for (i = 0; i < (**p).size; i++) {

for (j = 0; j < (**p).size; j++) {

(*p)->Mat[i][j] = 0;

}

}

// 합 초기화

(** p).sum = 0x0;

// 확인

/*

for (i = 0; i < (**p).size; i++) {

for (j = 0; j < (**p).size; j++) {

printf("%d", (*p)->Mat[i][j]);

if (j != (**p).size - 1) {

printf(" ");

}

}

printf("\n");

}

*/

} // end of size_setting function

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

void element_insert(Matrix** p) { // func (2)

int i, j;

srand((unsigned)time(NULL));

// 데이터 삽입

for (i = 0; i < (**p).size; i++) {

for (j = 0; j < (**p).size; j++) {

(*p)->Mat[i][j] = rand() % 20 + 1;

}

}

for (i = 0; i < (**p).size; i++) {

for (j = 0; j < (**p).size; j++) {

printf("%02d", (*p)->Mat[i][j]);

if (j != (**p).size - 1) {

printf(" ");

}

}

printf("\n");

}

} // end of element_insert function 

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

void row_col_totalSum(Matrix** p) { // func (3)

int r = 0; // 행

int c = 0; // 열

int i;

while (1) {

printf("행 입력 : ");

scanf("%d", &r);

printf("열 입력 : ");

scanf("%d", &c);

if (r < 0 || r >=(** p).size) {

printf("행 값이 범위를 벗어납니다.\n");

}

else {

// r >= 0 && r < (** p).size

if (c < 0 || c >= (** p).size) {

printf("열 값이 범위를 벗어납니다.\n");

}

else {

break;

}

}

}

for (i = 0; i < (**p).size; i++) {

// 행에 대한 합

(** p).sum += (** p).Mat[r][i];

}

for (i = 0; i < (**p).size; i++) {

// 열에 대한 합

(** p).sum += (** p).Mat[i][c];

}


printf("입력한 값의 행과 열의 전체 합은 : %02d\n", (** p).sum);

} // end of row_col_totalSum function 

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

네이버 지식인 풀이  (0) 2018.11.14
네이버 지식인 답변  (0) 2018.11.12
네이버 풀이  (0) 2018.11.10
네이버 지식인 풀이  (0) 2018.11.07
네이버 지식인 풀이, c언어 숫자 거꾸로 출력  (0) 2018.11.03

네이버 풀이

언어/c언어2018. 11. 10. 17:36

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

# include <stdio.h>

# include <stdlib.h>

# include <math.h>

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

typedef struct {

double x_coor;

double y_coor;

double z_coor;

}Coord, *ptrCoord;

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

ptrCoord genNode(); //        func (1)

void init(Coord**); //        func (2)

void OnePrintf(Coord**); //   func (3)

void DotDistance(Coord**);//  func (4)

double Calc(Coord*, Coord*);//func (5)

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

void main(void) { // main function 

ptrCoord coodNode = NULL;

coodNode = genNode();

if (coodNode == NULL) {

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

exit(1);

}

init(&coodNode);

OnePrintf(&coodNode);

DotDistance(&coodNode);

// memory 해제

free(coodNode);

} // end of main function 

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

ptrCoord genNode() { // func (1) 

ptrCoord newNode = NULL;

newNode = (ptrCoord)malloc(sizeof(Coord) * 4);

return newNode;

} // end of genNode function 

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

void init(Coord** param) { // func (2)

int i, j; // index

double tmp[][3] = {

{ 00.510, 7.620, 15.230},

{ 04.320, 4.990, 07.190},

{ 06.780, 5.230, 02.690},

{ 12.430, 1.120, 23.110} }; // 4x3 행렬

            

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

j = 0x0;

((*param) + i)->x_coor = tmp[i][j++]; // x좌표

((*param) + i)->y_coor = tmp[i][j++]; // y좌표

((*param) + i)->z_coor = tmp[i][j];   // z좌표

}

} // end of init function 

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

void OnePrintf(Coord** param) { // func (3)

int i; // index

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

printf("%d번째 점의 : x : %0.3lf, y : %0.3lf, z : %0.3lf\n", i+1,

((*param) + i)->x_coor, ((*param) + i)->y_coor, ((*param) + i)->z_coor);

printf("\n");

} // end of OnePrintf function

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

void DotDistance(Coord** param) { // func (4)

int i, j; // index

double result = 0.;

int flag = 0;

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

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

if (i != j) {

printf("%d번째 점과 %d번째 점 사이의 거리는 : ", i+1, j+1);

result = Calc(((*param) + i), ((*param) + j));

printf("%0.3lf\n", result);

flag = 1;

}

}

if (flag) {

printf("\n");

flag = 0;

}

}

} // end of DotDistance function

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

double Calc(Coord* param1, Coord* param2) {

double retDouble = 0.;

retDouble = \

sqrt((pow(param1->x_coor - param2->x_coor, 2.0) +

  pow(param1->y_coor - param2->y_coor, 2.0) +

  pow(param1->z_coor - param2->z_coor, 2.0)), 2.0);

return retDouble;

} // end of Calc function 

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

네이버 지식인 답변  (0) 2018.11.12
네이버 지식인 풀이  (0) 2018.11.10
네이버 지식인 풀이  (0) 2018.11.07
네이버 지식인 풀이, c언어 숫자 거꾸로 출력  (0) 2018.11.03
네이버 지식인 풀이  (0) 2018.10.14

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

# include <stdio.h>

# include <string.h> 

# include <stdlib.h>

# include <Windows.h>

# include <conio.h>

# define LEN 60

# define ERROR_ 1

typedef struct {

char my_passwd[LEN];

char input_passwd[LEN];

}PASSWRD;

// function prototype

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

PASSWRD* ret_new_node();

void init(PASSWRD** param);

void password_write(PASSWRD** param);

void compare(PASSWRD** param);

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

int main(void) {

PASSWRD* mPass = NULL;

mPass = ret_new_node();

if (mPass == NULL) {

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

exit(ERROR_);

}

init(&mPass);

password_write(&mPass);

compare(&mPass);

free(mPass);

return 0;

} // end of main function

PASSWRD* ret_new_node() { // function (1)

PASSWRD* tmpNode = NULL;

tmpNode = (PASSWRD*)malloc(sizeof(PASSWRD));

return tmpNode;

} // end of ret_new_node function

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

void init(PASSWRD** param) { // function (2)

// 데이터 초기화 

strcpy((*param)->input_passwd, "\0");

strcpy((*param)->my_passwd, "\0");

// 패스워드 설정

strcpy((*param)->my_passwd, "hello1234");

} // end of init function

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

void password_write(PASSWRD** param) {

int i = 0; // index

printf("PassWord:  ");

while (1) {


if (_kbhit()) {

(*param)->input_passwd[i] = _getch();

if ((int)((*param)->input_passwd[i]) == 13) {

break;

}

i += 1;

printf("*");

//rewind(stdout);

}

}

printf("\n");

(*param)->input_passwd[i] = '\0';

printf("%s\n", (*param)->input_passwd);

} // end of password_write function 

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

void compare(PASSWRD** param) {

if (!strcmp((*param)->input_passwd, (*param)->my_passwd)) {

printf("same \n");

}

else {

printf("not same\n");

}

} // end of compare function 

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

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

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


# include <stdio.h>

# include <stdlib.h>

# include <string.h>

# define LEN 40

# define ERROR 1

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

typedef struct Num {

char sNum[LEN]; // 문자열

int iNum; // 정수

}Num, *ptrNum;

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

ptrNum newNode();            // func (1)

void Init(Num** p);          // func (2)

void ValueInsert(Num** p);   // func (3)

void ReversePrint(Num** p);  // func (4)

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

int main(void) {

ptrNum node = NULL;

node = newNode();

if (node == NULL) {

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

exit(ERROR);

}

else { // node != NULL

Init(&node);

ValueInsert(&node);

ReversePrint(&node);

}

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

return 0;

}

ptrNum newNode() { // func (1)

ptrNum retNode = NULL;

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

return retNode;

} // end of newNode function

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

void Init(Num** p) { // func (2)

(*p)->iNum = 0;

strcpy((*p)->sNum, "\0");

} // end of Init function

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

void ValueInsert(Num** p) {

printf("정수 입력:  ");

scanf("%d", &(*p)->iNum);

sprintf((*p)->sNum, "%d", (*p)->iNum);

//printf("%s\n", (*p)->sNum);

} // end of ValueInsert function 

void ReversePrint(Num** p) {

int i; // index

int num = strlen((*p)->sNum)-1;

for (i = num; i >= 0; i--) {

printf("%c", (*p)->sNum[i]);

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

} // end of ReversePrint function 

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

네이버 풀이  (0) 2018.11.10
네이버 지식인 풀이  (0) 2018.11.07
네이버 지식인 풀이  (0) 2018.10.14
네이버 지식인 풀이 링크드 리스트  (0) 2018.10.13
네이버 지식인 문제 풀이  (0) 2018.10.09