-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChapter05.c
92 lines (76 loc) · 1.15 KB
/
Chapter05.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <stdio.h>
int Add(int A, int B)
{
return A + B;
}
int Sub(int A, int B)
{
return A - B;
}
int Mul(int A, int B)
{
return A * B;
}
int Div(int A, int B)
{
return A / B;
}
void HowTo1(void)
{
printf("사칙연산 프로그램입니다.\n");
printf("두 정수를 입력해주세요: ");
}
void HowTo2(void)
{
printf("어떤 계산을 할까요?\n");
printf("1. 덧셈 2. 뺄셈 3. 곱셈 4. 나눗셈");
}
int ReadNum(void)
{
int num;
scanf_s("%d", &num);
return num;
}
int main(void)
{
int opt, result, num1, num2, A, B;
HowTo1();
num1 = ReadNum();
num2 = ReadNum();
if (num1 > num2)
{
A = num1;
B = num2;
}
else
{
A = num2;
B = num1;
}
while (1)
{
HowTo2();
opt = ReadNum();
if (opt < 1 || opt>4)
{
printf("잘못된 숫자\n");
continue;
}
break;
}
switch (opt)
{
case 1:
printf("%d+%d=%d\n", A, B, Add(A, B));
break;
case 2:
printf("%d-%d=%d\n", A, B, Sub(A, B));
break;
case 3:
printf("%d*%d=%d\n", A, B, Mul(A, B));
break;
case 4:
printf("%d/%d=%d\n", A, B, Div(A, B));
break;
}
}