-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimpleCalculator.c
136 lines (117 loc) · 3.77 KB
/
simpleCalculator.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include<stdio.h>
#include<math.h>
void add(int a, int b){
printf("The sum of %d and %d is %d\n", a, b, a+b);
}
void subtract(int a, int b){
printf("The difference of %d and %d is %d\n", a, b, a-b);
}
void multiply(int a, int b){
printf("The product of %d and %d is %d\n", a, b, a*b);
}
void divide(float a, float b){
printf("The division of %.2f and %.2f is %.2f\n", a, b, a/b);
}
void reminder(int a, int b){
printf("The reminder of %d and %d is %d\n", a, b, a%b);
}
int main(){
int choice;
do{
printf("-------------------------------------------------------------\n");
printf("Choose one of the following optionx to perform the operation:\n");
printf("\n1. Addition\n");
printf("2. Subtraction\n");
printf("3. Multiplication\n");
printf("4. Division\n");
printf("5. Reminder\n");
printf("6. Power\n");
printf("7. Square Root\n");
printf("8. Cube Root\n");
printf("9. Exit\n");
printf("\nEnter your choice: ");
scanf("%d", &choice);
printf("-------------------------------------------------------------\n");
if(choice == 1){
int a,b;
printf("enter the value of first number: ");
scanf("%d", &a);
printf("enter the value of second number: ");
scanf("%d", &b);
add(a,b);
}
else if(choice == 2){
int a,b;
printf("enter the value of first number: ");
scanf("%d", &a);
printf("enter the value of second number: ");
scanf("%d", &b);
subtract(a,b);
}
else if(choice == 3){
int a,b;
printf("enter the value of first number: ");
scanf("%d", &a);
printf("enter the value of second number: ");
scanf("%d", &b);
multiply(a,b);
}
else if(choice == 4){
int a,b;
printf("enter the value of first number: ");
scanf("%d", &a);
printf("enter the value of second number: ");
scanf("%d", &b);
if(a == 0 || b == 0){
printf("Division by zero is not possible\n");
}
else{
float x,y;
x = (float)a;
y = (float)b;
divide(x,y);
}
}
else if(choice == 5){
int a,b;
printf("enter the value of first number: ");
scanf("%d", &a);
printf("enter the value of second number: ");
scanf("%d", &b);
if(a == 0 || b == 0){
printf("Division by zero is not possible\n");
}
else{
reminder(a,b);
}
}
else if(choice == 6){
int a,b;
printf("enter the value of the base: ");
scanf("%d", &a);
printf("enter the value of the power: ");
scanf("%d", &b);
printf("the value of %d raised to the power %d is %d\n", a, b, (int)pow(a,b));
}
else if(choice == 7){
int a;
printf("enter the value of the number: ");
scanf("%d", &a);
printf("the square root of %d is %.2f\n", a, sqrt(a));
}
else if(choice == 8){
int a;
printf("enter the value of the number: ");
scanf("%d", &a);
printf("the cube root of %d is %.2f\n", a, cbrt(a));
}
else if(choice == 9){
printf("Exiting the program\n");
printf("------------------Created By Sohan Rout---------------------\n");
}
else{
printf("Invalid choice\n");
}
}while(choice != 9);
return 0;
}