-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassignment4.c
152 lines (83 loc) · 1.81 KB
/
assignment4.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include <stdio.h>
#define _CRT_SECURE_NO_WARNINGS
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;
}
float Div(int a, int b) {
return (float)a / b;
}
int Fac(int a) {
if (a == 1 || a == 0) {
return 1;
}
else {
return a * Fac(a - 1);
}
}
int main() {
char oper = '!';
while (oper != 'q') {
printf("연산자를 입력하세요. : ");
scanf_s("%c", &oper);
if (oper == '+') {
int a, b;
printf("두 숫자를 입력하세요. (value1 value 2) : ");
scanf_s("%d%d", &a, &b);
printf("결과값 : %d\n", Add(a, b));
getchar();
}
else if (oper == '-') {
int a, b;
printf("두 숫자를 입력하세요. (value1 value 2) : ");
scanf_s("%d%d", &a, &b);
printf("결과값 : %d\n", Sub(a, b));
getchar();
}
else if (oper == '*') {
int a, b;
printf("두 숫자를 입력하세요. (value1 value 2) : ");
scanf_s("%d%d", &a, &b);
printf("결과값 : %d\n", Mul(a, b));
getchar();
}
else if (oper == '/') {
int a, b;
b = 0;
while (b == 0) {
printf("두 숫자를 입력하세요. (value1 value 2) : ");
scanf_s("%d%d", &a, &b);
if (b == 0) {
printf("0으로는 나눌 수 없어요.\n");
}
}
printf("결과값 : %f\n", Div(a, b));
getchar();
}
else if (oper == '!') {
int a;
a = -1;
while (a<0) {
printf("숫자를 입력하세요. (value1) : ");
scanf_s("%d", &a);
if (a < 0) {
printf("0이상의 수를 입력하세요.\n");
}
}
printf("결과값 : %d\n", Fac(a));
getchar();
}
else if (oper == 'q') {
break;
}
else {
printf("연산자를 잘못 입력하였습니다.\n");
getchar();
}
}
}