-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculator.c
302 lines (290 loc) · 7.85 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define note "Please Enter the Valid Operation"
#define PI 3.14159265
void addition();
void subtraction();
void multiplication();
void division();
void modulus();
void factorial();
void power();
void square();
void cube();
void squareroot();
void logarithm();
void log_base_10();
void sine();
void cosine();
void tangent();
void sineh();
void cosineh();
void tangenth();
void arc_sine();
void arc_cosine();
void arc_tangenth();
int main(){
int i;
for(i=1;i<100;i++){
printf("*");
}
printf("\n\t\t\tWelcome to the scientific calculator!!\n");
for(i=1;i<100;i++){
printf("*");
}
printf("\n");
int choice;
printf("\nPress 0 to quit the program \n");
printf("Enter 1 for Addition \n");
printf("Enter 2 for Subtraction \n");
printf("Enter 3 for Multiplication \n");
printf("Enter 4 for Division \n");
printf("Enter 5 for Modulus \n");
printf("Enter 6 for Power \n");
printf("Enter 7 for Factorial \n");
printf("Enter 8 for Square \n");
printf("Enter 9 for Cube \n");
printf("Enter 10 for Squareroot \n");
printf("Enter 11 for Logarithm \n");
printf("Enter 12 for Log_base_10 \n");
printf("Enter 13 for Sine \n");
printf("Enter 14 for Cosine \n");
printf("Enter 15 for Tangent \n");
printf("Enter 16 for Sineh \n");
printf("Enter 17 for Cosineh \n");
printf("Enter 18 for Tangenth \n");
printf("Enter 19 for Sine inverse \n");
printf("Enter 20 for Cosine inverse \n");
printf("Enter 21 for Tangenth inverse \n\n");
for(i=1;i<100;i++){
printf("*");
}
while(1){
printf("\n\nEnter the operation you want to do: ");
scanf("%d",&choice);
switch(choice)
{
case 1:
addition();
break;
case 2:
subtraction();
break;
case 3:
multiplication();
break;
case 4:
division();
break;
case 5:
modulus();
break;
case 6:
power();
break;
case 7:
factorial();
break;
case 8:
square();
break;
case 9:
cube();
break;
case 10:
squareroot();
break;
case 11:
logarithm();
break;
case 12:
log_base_10();
break;
case 13:
sine();
break;
case 14:
cosine();
break;
case 15:
tangent();
break;
case 16:
sineh();
break;
case 17:
cosineh();
break;
case 18:
tangenth();
break;
case 19:
arc_sine();
break;
case 20:
arc_cosine();
break;
case 21:
arc_tangenth();
break;
case 0:
exit(0);
default:
printf("\n********** %s ***********\n",note);
}
}
return 0;
}
void addition(){
printf("\nEnter the numbers you want to add: ");
int a,b;
scanf("%d%d",&a,&b);
printf("The sum of %d and %d is %d\n",a,b,a+b);
}
void subtraction(){
printf("\nEnter the numbers you want to subtract: ");
int a,b;
scanf("%d%d",&a,&b);
printf("The subtraction of %d and %d is %d\n",a,b,a-b);
}
void multiplication(){
printf("\nEnter the numbers you want to multiply: ");
int a,b;
scanf("%d%d",&a,&b);
printf("The multiplication of %d and %d is %d\n",a,b,a*b);
}
void division(){
printf("\nEnter the numbers you want to divide: ");
int a,b;
scanf("%d%d",&a,&b);
printf("The division of %d and %d is %f\n",a,b,(float)a/(float)b);
}
void modulus(){
printf("\nEnter the numbers you want to find modulus of: ");
int a,b;
scanf("%d%d",&a,&b);
printf("The modulus of %d and %d is %d\n",a,b,a%b);
}
void factorial(){
int n,factorial;
printf("\nEnter the number you want the factorial of: ");
scanf("%d",&n);
factorial=1;
for(int i=1;i<=n;i++){
factorial=factorial*i; // factorial*=i;
}
printf("\nFactorial of %d is %d",n,factorial);
}
void power(){
double b;
double p;
printf("\nEnter the base and the power: ");
scanf("%lf%lf",&b,&p);
double e=pow(b,p);
printf("The power is %lf",e);
}
void square(){
double b;
printf("\nEnter the number you want the square of: ");
scanf("%lf",&b);
double p=pow(b,2);
printf("The square of %lf is %lf",b,p);
}
void cube(){
double b;
printf("\nEnter the number you want the cube of: ");
scanf("%lf",&b);
double p=pow(b,3);
printf("The cube of %lf is %lf",b,p);
}
void squareroot(){
double b;
printf("\nEnter the number you want the square root of : ");
scanf("%lf",&b);
double s = sqrt(b);
printf("The square root of %lf is %lf",b,s);
}
void logarithm(){
double b;
printf("\nEnter the number you want the natural logarithm (base = e) of : ");
scanf("%lf", &b);
double l = log(b);
printf("The natural log of %lf is %lf\n",b,l);
}
void log_base_10(){
double b;
printf("\nEnter the number you want the log base 10 of : ");
scanf("%lf",&b);
double l = log10(b);
printf("The logarithm base 10 of %lf is %lf\n",b,l);
}
void sine(){
double b;
printf("\nEnter the number you want the sine of : ");
scanf("%lf",&b);
double s = sin (b*PI/180);
printf("The sine of %lf is %lf\n",b,s);
}
void cosine(){
double b;
printf("\nEnter the number you want the cosine of : ");
scanf("%lf",&b);
double c = cos (b*PI/180);
printf("The cosine of %lf is %lf\n",b,c);
}
void tangent(){
double b;
printf("\nEnter the number you want the tangent of : ");
scanf("%lf",&b);
double t = tan (b*PI/180);
printf("The tangent of %lf is %lf\n",b,t);
}
void sineh(){
double b;
printf("\nEnter the number you want the sineh of : ");
scanf("%lf",&b);
double s = sinh(b);
printf("The sineh of %lf is %lf\n",b,s);
}
void cosineh(){
double b;
printf("\nEnter the number you want the cosineh of : ");
scanf("%lf",&b);
double c = cosh(b);
printf("The cosineh of %lf is %lf\n",b,c);
}
void tangenth(){
double b;
printf("\nEnter the number you want the tangenth of : ");
scanf("%lf",&b);
double t = tanh(b);
printf("The tangenth of %lf is %lf\n",b,t);
}
void arc_sine(){
double b;
printf("\nEnter the number you want the sine inverse of : ");
scanf("%lf",&b);
double as = asin(b);
printf("Inverse of sin(%lf) = %lf in radians\n",b,as);
as = asin(b)*180/PI;
printf("Inverse of sin(%lf) = %lf in degrees\n",b,as);
}
void arc_cosine(){
double b;
printf("\nEnter the number you want the cosine inverse of : ");
scanf("%lf",&b);
double ac = acos(b);
printf("Inverse of cos(%lf) = %lf in radians\n",b,ac);
ac = acos(b)*180/PI;
printf("Inverse of cos(%lf) = %lf in degrees\n",b,ac);
}
void arc_tangenth(){
double b;
printf("\nEnter the number you want the tangenth inverse of : ");
scanf("%lf",&b);
double at = atan(b);
printf("Inverse of tan(%lf) = %lf in radians\n",b,at);
at = atan(b)*180/PI;
printf("Inverse of tan(%lf) = %lf in degrees\n",b,at);
}