forked from MAYANK25402/Hactober-2023-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculator.c
40 lines (31 loc) · 768 Bytes
/
Calculator.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
#include <stdio.h>
int main() {
char op;
float num1, num2;
printf("Enter operator either + or - or * or /: ");
scanf("%c", &op);
printf("Enter two operands: ");
scanf("%f %f", &num1, &num2);
switch(op) {
case '+':
printf("%.2f", num1+num2);
break;
case '-':
printf("%.2f", num1-num2);
break;
case '*':
printf("%.2f", num1*num2);
break;
case '/':
if(num2 == 0) {
printf("Error: Division by zero");
} else {
printf("%.2f", num1/num2);
}
break;
default:
printf("Error: Invalid operator");
break;
}
return 0;
}