-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple calculator(using c)
53 lines (52 loc) · 1.31 KB
/
simple calculator(using 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
#include <stdio.h>
#include<stdlib.h>
int main()
{
char ch,x;
double a,b;
while(1)
{
printf("enter any operation(+,-,*,/),if you want exit press x::\t");
scanf(" %c",&ch);
if(ch=='x')
{
printf("you are exited");
exit(0);
}
printf("enter first operand::\t");
scanf("%lf",&a);
printf("enter second operand::\t");
scanf("%lf",&b);
switch(ch)
{
//AXxdiition::
case '+':
printf("%.1lf + %.1lf = %.1lf\n",a,b,a+b);
break;
//Substraction::
case '-':
printf("%.1lf - %.1lf = %.1lf\n",a,b,a-b);
break;
//Multiplication::
case '*':
printf("%.1lf * %.1lf = %.1lf\n",a,b,a*b);
break;
//Division::
case '/':
if(b!=0)
{
printf("%.1lf / %.1lf = %.1lf\n",a,b,a/b);
}
else
{
printf("Error! Division by zero is not allowed.\n");
}
break;
default:
{
printf("Error!,please enter the valid input!!");
}
}
printf("\n");
}
}