-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator_switch_goto.c
More file actions
60 lines (48 loc) · 1.42 KB
/
Copy pathcalculator_switch_goto.c
File metadata and controls
60 lines (48 loc) · 1.42 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
/*
Problem Statement: Write a C program for a simple calculator that performs addition, subtraction, multiplication, division,
and modulus using switch-case and allows the user to repeat via goto.
*/
#include<stdio.h>
int main() {
int ch, c;
int num1, num2, add, sub, mul, rem;
float div;
menu:
printf("\nEnter any 2 numbers: ");
scanf("%d%d", &num1, &num2);
printf("\n1. Addition. \n2. Subtraction. \n3. Multiplication. \n4. Division. \n5. Reminder.");
printf("\nEnter your choice: ");
scanf("%d", &ch);
switch (ch)
{
case 1:
add = num1 + num2;
printf("\nAddition of %d and %d is %d.", num1, num2, add);
break;
case 2:
sub = num1 - num2;
printf("\nSubtraction of %d and %d is %d.", num1, num2, sub);
break;
case 3:
mul = num1 * num2;
printf("\nMultiplication of %d and %d is %d.", num1, num2, mul);
break;
case 4:
div = (float)num1 / (float)num2;
printf("\nDivision of %d and %d is %f.", num1, num2, div);
break;
case 5:
rem = num1 % num2;
printf("\nReminder of %d and %d is %d.", num1, num2, rem);
break;
default:
printf("Invalid Case!!!");
}
printf("\nDo you want to continue with Caculator(Press 1): ");
scanf("%d", &c);
if (c == 1)
{
goto menu;
}
printf("\nThank you!!!");
}