-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfourteen.c
More file actions
40 lines (34 loc) · 1.03 KB
/
fourteen.c
File metadata and controls
40 lines (34 loc) · 1.03 KB
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() {
int n, a, b;
float result;
printf("Enter the value for a - ");
scanf("%d", &a);
printf("Enter the value for b - ");
scanf("%d", &b);
printf("\nChoose one option out of four!\n");
printf("1. Addition\n2. Subtraction\n3. Division\n4. Multiplication\n");
printf("Press 1 to 4 - ");
scanf("%d", &n);
switch(n) {
case 1: result = a + b;
printf("Addition = %.2f\n", result);
break;
case 2: result = a - b;
printf("Subtraction = %.2f\n", result);
break;
case 3:
if(b != 0) {
result = (float)a / b;
printf("Division = %.2f\n", result);
} else {
printf("Cannot divide by zero!\n");
}
break;
case 4: result = a * b;
printf("Multiplication = %.2f\n", result);
break;
default: printf("Please choose a valid option (1-4)!\n");
}
return 0;
}