-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator Program
More file actions
33 lines (32 loc) · 806 Bytes
/
Copy pathCalculator Program
File metadata and controls
33 lines (32 loc) · 806 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
#include <stdio.h>
int main() {
int a, b;
char op;
printf("Enter two numbers: ");
scanf("%d%d", &a, &b);
getchar();
printf("Enter an operator (+, -, *, /): ");
scanf("%c", &op);
switch (op) {
case '+':
printf("Addition is %d\n", a + b);
break;
case '-':
printf("Subtraction is %d\n", a - b);
break;
case '*':
printf("Multiplication is %d\n", a * b);
break;
case '/':
if (b != 0) {
printf("Division is %d\n", a / b);
} else {
printf("Error: Division by zero is not allowed.\n");
}
break;
default:
printf("Invalid operator.\n");
break;
}
return 0;
}