-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathSimple_Calculator.c
More file actions
39 lines (31 loc) · 850 Bytes
/
Copy pathSimple_Calculator.c
File metadata and controls
39 lines (31 loc) · 850 Bytes
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
#include <stdio.h>
#include <stdlib.h>
int main()
{
char ch;
double a, b;
while (1) {
printf("Enter an operator (+, -, *, /), if want to exit press x: ");
scanf(" %c", &ch);
if (ch == 'x')
exit(0);
printf("Enter two first and second operand: ");
scanf("%lf %lf",&a,&b);
switch (ch) {
case '+':
printf("%.1lf + %.1lf = %.1lf\n", a, b, a + b);
break;
case '-':
printf("%.1lf - %.1lf = %.1lf\n", a, b, a - b);
break;
case '*':
printf("%.1lf * %.1lf = %.1lf\n", a, b, a * b);
break;
case '/':
printf("%.1lf / %.1lf = %.1lf\n", a, b, a / b);
break;
default:
printf("Error! please write a valid operator\n");
}
}
}