본문 바로가기
솔루션모음/쉽게 풀어 쓴 C언어 Express 실습문제

[쉽게 풀어 쓴 C언어 Express] 9장 프로그래밍 programming 솔루션 답지

by 이얏호이야호 2020. 4. 11.

쉽게 풀어 쓴 C언어 express 솔루션입니다.
파일을 따로 준비해놨으니 필요하시다면 다운받아서 사용해주세요^^

1.

#include <stdio.h>

int add(int, int);

int sub(int, int);

int mul(int, int);

int div(int, int);

int main(void) {

 char op;

 int x, y;

 int i;

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

 printf("연산을 입력하시오: ");

 scanf("%d %c %d", &x, &op, &y);

 if( op == '+' )

 printf("연산 결과: %d \n", add(x, y)); else if( op == '-' )

 printf("연산 결과: %d \n", sub(x, y)); else if( op == '*' )

 printf("연산 결과: %d \n", mul(x, y)); else if( op == '/' )

 printf("연산 결과: %d \n", div(x, y)); else

 printf("지원되지 않는 연산자입니다. \n");

 }

 return 0;

}

int add(int x, int y) {

 static int count;

 count++;

 printf("덧셈은 총 %d번 실행되었습니다.\n", count);

 return (x+y);

}

int sub(int x, int y) {

 static int count;

 count++;

 printf("뺄셈은 총 %d번 실행되었습니다.\n", count);

 return (x-y);

}

int mul(int x, int y) {

 static int count;

 count++;

 printf("곱셈은 총 %d번 실행되었습니다.\n", count);

 return (x*y);

}

int div(int x, int y) {

 static int count;

 count++;

 printf("나눗셈은 총 %d번 실행되었습니다.\n", count);

 return (x/y);

}

 

2.

#include <stdio.h>

#include <stdlib.h>

void get_dice_face();

int main(void) {

 int i;

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

 get_dice_face();

 return 0;

}

void get_dice_face() {

 static int one, two, three, four, five, six;

 int face ;

 face = rand() %6;

 if( face == 0 ) one++; else if( face == 1 ) two++; else if( face == 2 ) three++; else if( face == 3 ) four++; else if( face == 4 ) five++; else six++;

 printf("%d %d %d %d %d %d\n", one, two, three, four, five, six);

}

 

 

3.

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

int get_random () {

 static int inited=0;

 if( inited == 0 ) {

 printf("초기화 실행\n");

 srand((unsigned)time(NULL));

 inited = 1;

 }

 return rand();

}

int main(void) {

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

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

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

 return 0;

}

 

 

 

 

4.

#include <stdio.h>

double recursive(int n) {

 if( n==1 ) return 1; else return 1.0/n+recursive(n-1);

}

int main(void) {

 printf("%f\n", recursive(10));

 return 0;

}

 

 

5.

#include <stdio.h>

#include <stdlib.h>

void save();

void draw();

int balance;

int main(void) {

 int menu;

 while(1) {

 printf("메뉴를 선택하세오: 저축(1), 인출(2): ");

 scanf("%d", &menu);

 if( menu == 1 )

 save(); else if( menu == 2 )

 draw(); else

 break;

 printf("현재 잔액은 %d입니다.\n", balance);

 }

 return 0;

}

void save() {

 int amount;

 printf("저축할 금액: ");

 scanf("%d", &amount);

 balance += amount;

}

void draw() {

 int amount;

 printf("인출할 금액: ");

 scanf("%d", &amount);

 balance -= amount;

}

 

 

6.

#include <stdio.h>

int get_tri_number(int n) {

 if( n==1 ) return 1; else return n+get_tri_number(n-1);

}

int main(void) {

 printf("%d\n", get_tri_number(4));

 return 0;

}

 

 

7.

#include <stdio.h>

int recursive(int n, int k) {

 if( n==1 || n ==k) return 1; else return recursive(n-1, k-1)+ recursive(n-1, k);

}

int main(void) {

 printf("%d\n", recursive(3,2));

 return 0;

}

 

 

8.

#include <stdio.h>

int show_digit(int x) {

 if( x/10 > 0 )

 show_digit(x/10);

 printf("%d ", x%10);

}

int main(void) {

 int n;

 printf("정수를 입력하시오: ");

 scanf("%d", &n);

 show_digit(n);

 return 0;

}

 

 

 

 

 

 

 

 

 

더 많은  쉽게 풀어 쓴 C언어EXPRESS 이론 솔루션

 https://chuinggun.tistory.com/category/%EC%86%94%EB%A3%A8%EC%85%98%EB%AA%A8%EC%9D%8C/%EC%89%BD%EA%B2%8C%20%ED%92%80%EC%96%B4%20%EC%93%B4%20C%EC%96%B8%EC%96%B4%20Express%20%EC%9D%B4%EB%A1%A0

더 많은 쉽게 풀어 쓴 C언어EXPRESS 프로그래밍 솔루션 : 

https://chuinggun.tistory.com/category/%EC%86%94%EB%A3%A8%EC%85%98%EB%AA%A8%EC%9D%8C/%EC%89%BD%EA%B2%8C%20%ED%92%80%EC%96%B4%20%EC%93%B4%20C%EC%96%B8%EC%96%B4%20Express%20%EC%8B%A4%EC%8A%B5%EB%AC%B8%EC%A0%9C

댓글