-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion(2)main.c
More file actions
38 lines (32 loc) · 987 Bytes
/
Question(2)main.c
File metadata and controls
38 lines (32 loc) · 987 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
#include <stdio.h>
int main() {
char operator;
float num1 , num2;
printf("Enter operator (+, -, *, /): ");
scanf(" %c", &operator);
printf("Enter first operand: ");
scanf("%f", &num1);
printf("Enter second operand: ");
scanf("%f", &num2);
switch (operator) {
case '+':
printf("%.2f + %.2f = %.2f\n", num1, num2, num1 + num2);
break;
case '-':
printf("%.2f - %.2f = %.2f\n", num1, num2, num1 - num2);
break;
case '*':
printf("%.2f * %.2f = %.2f\n", num1, num2, num1 * num2);
break;
case '/':
if (num2 != 0) {
printf("%.2f / %.2f = %.2f\n", num1, num2, num1 / num2);
} else {
printf("Error! Division by zero is not allowed.\n");
}
break;
default:
printf("Error! Invalid operator.\n");
}
return 0;
}