-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.c
69 lines (60 loc) · 1.64 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
// This is Calculator
// Version 1.0
#include <stdio.h>
int main()
{
int select;
float num1, num2, sum, sub, mul, percentage;
float div;
char ch;
printf("\nFor calculate percentage select YES or NO [YES = 1, NO = 2]: ");
scanf("%d", &select);
switch (select)
{
// here the code of %
case 1:
{
printf("\nEnter the number for checking percentage [ex: 10%%]: ");
scanf("%f",&num1);
percentage = num1 / 100;
printf("\nThe percentage of %.2f%% is: %.2f ", num1, percentage);
break;
}
// here the code of +,-,*,/
case 2:
{
printf("\nEnter two number to calculate(+,-,*,/ or %%): ");
scanf("%f%c%f", &num1, &ch, &num2);
if (ch == '+')
{
//addition
sum = num1 + num2;
printf("%.2f %c %.2f = %.2f", num1, ch, num2, sum);
}
else if (ch == '-')
{
//subtraction
sub = num1 - num2;
printf("%.2f %c %.2f = %.2f", num1, ch, num2, sub);
}
else if (ch == '*')
{
//multiplication
mul = num1 * num2;
printf("%.2f %c %.2f = %.2f", num1, ch, num2, mul);
}
else if (ch == '/')
{
//division
div = num1 / num2;
printf("%.2f %c %.2f = %.2f", num1, ch, num2, div);
}
break;
}
default:
{
printf("\nError.");
}
}
return 0;
}