-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator-switch-case.c
48 lines (46 loc) · 1.18 KB
/
calculator-switch-case.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<stdio.h>
#include<conio.h>
int main()
{
int operator=0;
float a,b,result;
printf("\n Choose an Operation \n"
"\t 1) Addition \n "
"\t 2) Subtraction \n"
"\t 3) Multiplication \n"
"\t 4) Division \n"
"\t 5) Remainder Calculation \n");
printf("Enter the option number : ");
scanf("%d",&operator);
printf("\nEnter the first Operand : ");
scanf("%f",&a);
printf("\nEnter the second Operand : ");
scanf("%f",&b);
printf("\n");
switch (operator)
{
case 1:
result = a+b;
printf(" %f + %f = %f",a,b,result);
break;
case 2:
result = a-b;
printf(" %f - %f = %f",a,b,result);
break;
case 3:
result = a*b;
printf(" %f * %f = %f",a,b,result);
break;
case 4:
result = a / b;
printf(" %f / %f = %f",a,b,result);
break;
case 5:
result = (int)a % (int)b;
printf(" %f // %f = %d",a,b,(int)result);
break;
default:
printf("Error!! invalid choice.");
}
return 0;
}