-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitchcalc.c
39 lines (30 loc) · 894 Bytes
/
switchcalc.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
//switch case calculator with char
#include <stdio.h>//preprocessor directive
int main()//body of code
{
float num1,num2,total;
char a;
printf("enter two numbers\n");
scanf("%f %f",&num1,&num2);//float used for proper output else integer mai 5/6 mai quotient 0 aayega jo wrong hai
printf("enter operation\n");
scanf(" %c", &a);//space must while using char data type
switch(a)
{
case '+':
printf("result: %f\n", num1+num2);
break;
case '-':
printf("result: %f\n", num1-num2);
break;
case '*':
printf("result: %f\n", num1*num2);
break;
case '/':
printf("result: %.2f\n", num1/num2);// %.2f means output upto two decimal place
break;
default:
printf("enter valid operation");
break;
}
return 0;
}