-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculator.c
55 lines (55 loc) · 1.88 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
#include <stdio.h>
int main()
{
char op;
int no1,no2;
float output;
printf("Enter what you want to do (+, -, *, /) :");
scanf("%c",&op);
printf (" \n Enter first number :");
scanf(" %d", &no1); // take first number
printf (" Enter second number :");
scanf (" %d", &no2); // take second number
switch (op)
{
case '+': output=no1+no2; // adding the two numbers.
printf ("The Sum of %d and %d is: %.2f",no1,no2,output);
break;
case '-': output=no1-no2; // subtracting the two numbers.
printf ("The Subtraction of %d and %d is:%.2f",no1,no2,output);
break;
case '*': output=no1*no2; // multiplying the two numbers
printf ("The Product of %d and %d is:%.2f",no1,no2,output);
break;
case '/':
if (no2 == 0) // if n2 == 0, division is undefined.
{
printf ("Invalid Argument");
scanf ("%d", &no2);
}
output=no1/no2; // dividing the two numbers
printf ("Division of %d and %d is: %.2f",no1,no2,output);
break;
/* if(no1==0.0)
{
printf("0");
break;
}
else if(no2==0.0)
{
printf("Invalid Argument");
break;
}
else
{
output=no1/no2;
printf("%lf/%lf=%lf",no1,no2,output);
break;
}
} */
default:
printf("Invalid Operation");
break;
}
return 0;
}