-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCalc.c
33 lines (29 loc) · 760 Bytes
/
Calc.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
// operator_calculator.c
#include <stdio.h>
int main() {
float num1, num2, result;
char operator;
printf("Enter two numbers: ");
scanf("%f %f", &num1, &num2);
printf("Enter operator (+, -, *, /): ");
scanf(" %c", &operator);
if (operator == '+') {
result = num1 + num2;
} else if (operator == '-') {
result = num1 - num2;
} else if (operator == '*') {
result = num1 * num2;
} else if (operator == '/') {
if (num2 != 0) {
result = num1 / num2;
} else {
printf("Error: Division by zero!\n");
return 1;
}
} else {
printf("Invalid operator!\n");
return 1;
}
printf("Result: %.2f\n", result);
return 0;
}