forked from PrabhudeepSingh/C-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculatorUsingSwitch.c
More file actions
41 lines (31 loc) · 1001 Bytes
/
CalculatorUsingSwitch.c
File metadata and controls
41 lines (31 loc) · 1001 Bytes
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
//Program to implement switch statement (Calculator using switch statement)
#include<stdio.h>
#include<conio.h>
int main()
{
char opt;
float num1,num2;
printf("Enter + for addition\n");
printf("Enter - for subtraction\n");
printf("Enter * for multiplication\n");
printf("Enter / for division\n");
printf("\nEnter your choice here : ");
opt=getche();
printf("\n\nEnter 1st number : ");
scanf("%f",&num1);
printf("Enter 2nd number : ");
scanf("%f",&num2);
switch(opt)
{
case '+' : printf("\n\nSum of %.2f and %.2f = %.2f\n",num1,num2,num1+num2);
break;
case '-' : printf("\n\nDifference of %.2f and %.2f = %.2f\n",num1,num2,num1-num2);
break;
case '*' : printf("\n\nMultiplication of %.2f and %.2f = %.2f\n",num1,num2,num1*num2);
break;
case '/' : printf("\n\nDivision of %.2f and %.2f = %.2f\n",num1,num2,num1/num2);
break;
default : printf("\nwrong input");
}
return 0;
}