728x90
728x170
쉽게 풀어 쓴 C언어 Express 9장 프로그래밍 문제 해설
쉽게 풀어 쓴 C언어 Express 9장 프로그래밍 문제 해설
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);
}
삶의 동기가 부족하다면 배달알바 해봐라
인터넷에서 유명한 글인 삶의 동기가 부족하다면 배달알바 해봐라에 대해 알아보도록 하겠습니다. 이 글을 처음부터 끝까지 읽어주시면 삶의 동기가 부족하다면 배달알바 해봐라에 대해 아는
tistorysolution.tistory.com
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;
}
스포츠카를 못타는 인생은 진짜 불쌍한 인생이다
인터넷에서 유명한 글인 스포츠카를 못타는 인생은 진짜 불쌍한 인생이다에 대해 알아보도록 하겠습니다. 이 글을 처음부터 끝까지 읽다 보면 스포츠카를 못타는 인생은 진짜 불쌍한 인생이다
tistorysolution.tistory.com
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;
}
순자산 8.4억이면 상위 10%.JPG
인터넷에서 유명한 글인 순자산 8.4억이면 상위 10%에 대해 알아보도록 하겠습니다. 이 글을 처음부터 끝까지 읽다 보면 순자산 8.4억이면 상위 10%에 대해 아는데 도움이 될 것입니다. 순자산 8.4
tistorysolution.tistory.com
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;
}
반박환영) 우리나라에서 살만한 동네 최종 6곳
인터넷에서 화제인 우리나라에서 살만한 동네 최종 6곳에 대해 알아보도록 하겠습니다. 이 글을 처음부터 끝까지 읽다 보면 우리나라에서 살만한 동네 최종 6곳에 대해 아는데 도움이 될 것입니
tistorysolution.tistory.com
728x90
그리드형
'IT > 프로그래밍' 카테고리의 다른 글
쉽게 풀어 쓴 C언어 Express 11장 프로그래밍 문제 해설 (0) | 2020.12.10 |
---|---|
쉽게 풀어 쓴 C언어 Express 10장 프로그래밍 문제 해설 (0) | 2020.12.10 |
쉽게 풀어 쓴 C언어 Express 8장 프로그래밍 문제 해설 (1) | 2020.12.09 |
쉽게 풀어 쓴 C언어 Express 7장 프로그래밍 문제 해설 (0) | 2020.12.09 |
쉽게 풀어 쓴 C언어 Express 6장 프로그래밍 문제 해설 (0) | 2020.12.08 |
댓글