-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeAlpha_BasicCalculator.c
More file actions
81 lines (67 loc) · 2.06 KB
/
Copy pathCodeAlpha_BasicCalculator.c
File metadata and controls
81 lines (67 loc) · 2.06 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include<stdio.h>
int main() {
while(1) {
int ch;
printf("\n=== Basic Calculator ===\n");
printf("1) Addition\n");
printf("2) Subtraction\n");
printf("3) Multiplication\n");
printf("4) Division\n");
printf("5) Exit\n");
printf("Enter your choice: ");
scanf("%d", &ch);
if(ch == 5) {
printf("Exiting...\n");
break;
}
switch(ch) {
case 1: {
int a, b;
printf("Enter first number: ");
scanf("%d", &a);
printf("Enter second number: ");
scanf("%d", &b);
int c = a + b;
printf("Sum = %d\n", c);
break;
}
case 2: {
int a, b;
printf("Enter first number: ");
scanf("%d", &a);
printf("Enter second number: ");
scanf("%d", &b);
int c = a - b;
printf("Difference = %d\n", c);
break;
}
case 3: {
int a, b;
printf("Enter first number: ");
scanf("%d", &a);
printf("Enter second number: ");
scanf("%d", &b);
int c = a * b;
printf("Product = %d\n", c);
break;
}
case 4: {
float a, b;
printf("Enter first number: ");
scanf("%f", &a);
printf("Enter second number: ");
scanf("%f", &b);
if(b == 0) {
printf("Division by zero is not possible.\n");
} else {
float c = a / b;
printf("Quotient = %.2f\n", c);
}
break;
}
default:
printf("Invalid choice! Please try again.\n");
}
}
return 0;
}