Skip to content

Commit 28c8a14

Browse files
authored
Update Chapter05.c
1 parent 55c3d31 commit 28c8a14

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

Chapter05.c

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

0 commit comments

Comments
 (0)