-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator.c
70 lines (69 loc) · 1.9 KB
/
calculator.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<stdio.h>
int main()
{
char opt;
int n1,n2;
float sol;
printf("Choose operator amuong +,-,/,* : \n");
scanf("%c", &opt);
if(opt== '+')
{
printf("You have choosed Addition\n");
printf("Enter first numbers : \n");
scanf("%d",&n1);
printf("Enter second numbers : \n");
scanf("%d",&n2);
}
if(opt== '-')
{
printf("You have choosed Subtraction\n");
printf("Enter first numbers : \n");
scanf("%d",&n1);
printf("Enter second numbers : \n");
scanf("%d",&n2);
}
if(opt== '*')
{
printf("You have choosed Multiplication\n");
printf("Enter first numbers : \n");
scanf("%d",&n1);
printf("Enter second numbers : \n");
scanf("%d",&n2);
}
if(opt== '/')
{
printf("You have choosed Division\n");
printf("Enter first numbers : \n");
scanf("%d",&n1);
printf("Enter second numbers : \n");
scanf("%d",&n2);
}
switch(opt)
{
case '+' :
sol=n1+n2;
printf("Addition of %d and %d is %.2f\n",n1,n2,sol);
break;
case '-' : sol=n1-n2;
printf("Subtraction of %d and %d is %.2f\n",n1,n2,sol);
break;
case '*' : sol=n1*n2;
printf("Multiplication of %d and %d is %.2f\n",n1,n2,sol);
break;
case '/' : if(n2==0)
{
printf("Denominator can not be zero please choose right number : \n");
scanf("%d",&n2);
sol=n1/n2;
printf("Division of %d and %d is %.2f\n",n1,n2,sol);
}
else{
sol=n1/n2;
printf("Division of %d and %d is %.2f\n",n1,n2,sol);
}
break;
default :
printf("Something went wrong please check the options.");
}
return 0;
}