-
Notifications
You must be signed in to change notification settings - Fork 0
/
Basic_Calculator_In_C.c
379 lines (377 loc) · 10.4 KB
/
Basic_Calculator_In_C.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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#include<stdio.h>
#include<conio.h>s
#include<windows.h>
#include<math.h>
int var;
void Integer_ArithMetic_Function() {
printf("Welcome To Arithmetic Calculator\n");
printf("=============================================================\nPress Enter For Operation. Press Esc For Go Back!!!\n");
var = getch();
if(var == 27) {
system("Cls");
first_page();
} else if(var == 13) {
int num1, num2, option;
printf("=============================================================\n");
printf("Enter Input1 Value : ");
scanf("%d",&num1);
printf("Enter Input2 Value : ");
scanf("%d",&num2);
printf("=============================================================\n");
printf("Choose An Arithmetic Option : \n");
printf("1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n5. Modulo\nOption: ");
scanf("%d",&option);
switch(option) {
case 1:
printf("Result: %d",(num1 + num2));
printf("\n\nPress Enter Key To Reset, Press Esc To Go Back!!! ");
if(getch() == 13) {
system("Cls");
Integer_ArithMetic_Function();
} else {
system("Cls");
first_page();
}
break;
case 2:
printf("Result: %d",(num1 - num2));
printf("\n\nPress Enter Key To Reset, Press Esc To Go Back!!! ");
if(getch() == 13) {
system("Cls");
Integer_ArithMetic_Function();
}
if(getch() == 27) {
system("Cls");
first_page();
} else {
system("Cls");
first_page();
}
break;
case 3:
printf("Result: %d",(num1 * num2));
printf("\n\nPress Enter Key To Reset, Press Esc To Go Back!!! ");
if(getch() == 13) {
system("Cls");
Integer_ArithMetic_Function();
} else {
system("Cls");
first_page();
}
break;
case 4:
printf("Result: %d",(num1 / num2));
printf("\n\nPress Enter Key To Reset, Press Esc To Go Back!!! ");
if(getch() == 13) {
system("Cls");
Integer_ArithMetic_Function();
} else {
system("Cls");
first_page();
}
break;
case 5:
printf("Result: %d",(num1 % num2));
printf("\n\nPress Enter Key To Reset, Press Esc To Go Back!!! ");
if(getch() == 13) {
system("Cls");
Integer_ArithMetic_Function();
} else {
system("Cls");
first_page();
}
break;
default:
printf("\nInvalid Option Selection!!!");
Sleep(2000);
system("Cls");
Integer_ArithMetic_Function();
break;
}
}
}
void Float_Arithmetic_Function() {
printf("Welcome To Floating Calculator\n");
printf("=============================================================\nPress Enter For Operation. Press Esc For Go Back!!!\n");
var = getch();
if(var == 27) {
system("Cls");
first_page();
} else if(var == 13) {
float num1, num2;
int option;
printf("=============================================================\n");
printf("Enter Input1 Value : ");
scanf("%f",&num1);
printf("Enter Input2 Value : ");
scanf("%f",&num2);
printf("=============================================================\n");
printf("Choose An Arithmetic Option : \n");
printf("1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n5. Modulo\nOption: ");
scanf("%d",&option);
switch(option) {
case 1:
printf("Result: %f",(num1 + num2));
printf("\n\nPress Enter Key To Reset, Press Esc To Go Back!!! ");
if(getch() == 13) {
system("Cls");
Float_Arithmetic_Function();
} else {
system("Cls");
first_page();
}
break;
case 2:
printf("Result: %f",(num1 - num2));
printf("\n\nPress Enter Key To Reset, Press Esc To Go Back!!! ");
if(getch() == 13) {
system("Cls");
Float_Arithmetic_Function();
}
if(getch() == 27) {
system("Cls");
first_page();
} else {
system("Cls");
first_page();
}
break;
case 3:
printf("Result: %f",(num1 * num2));
printf("\n\nPress Enter Key To Reset, Press Esc To Go Back!!! ");
if(getch() == 13) {
system("Cls");
Float_Arithmetic_Function();
} else {
system("Cls");
first_page();
}
break;
case 4:
printf("Result: %f",(num1 / num2));
printf("\n\nPress Enter Key To Reset, Press Esc To Go Back!!! ");
if(getch() == 13) {
system("Cls");
Float_Arithmetic_Function();
} else {
system("Cls");
first_page();
}
break;
case 5:
printf("Result: %f",fmod(num1,num2));
printf("\n\nPress Enter Key To Reset, Press Esc To Go Back!!! ");
if(getch() == 13) {
system("Cls");
Float_Arithmetic_Function();
} else {
system("Cls");
first_page();
}
break;
default:
printf("\nInvalid Option Selection!!!");
Sleep(2000);
system("Cls");
Float_Arithmetic_Function();
break;
}
}
}
void Percentage_Calculation() {
printf("Welcome To Percentage Calculator\n");
printf("=============================================================\nPress Enter For Operation. Press Esc For Go Back!!!\n");
var = getch();
if(var == 27) {
system("Cls");
first_page();
} else if(var == 13) {
int opt1, val1, val2, val3;
printf("1. Percentage Of A Single Value\n2. Percentage Between Two Value\n");
printf("Choose Option : ");
scanf("%d",&opt1);
switch(opt1) {
case 1:
printf("=============================================================\n");
printf("Percentage Of A Single Value : \n");
printf("Enter A Value : ");
scanf("%d",&val1);
printf("\nOutput : %f",((float)val1 / 100));
printf("\n\nPress Enter Key To Reset, Press Esc To Go Back!!! ");
if(getch() == 13) {
system("Cls");
Percentage_Calculation();
} else {
system("Cls");
first_page();
}
break;
case 2:
printf("=============================================================\n");
printf("Percentage Between Two Value : \n");
printf("Enter First Input : ");
scanf("%d",&val2);
printf("Enter Second Value : ");
scanf("%d",&val3);
printf("\nOutput : %f",((float)val2 / 100 * val3));
printf("\n\nPress Enter Key To Reset, Press Esc To Go Back!!! ");
if(getch() == 13) {
system("Cls");
Percentage_Calculation();
} else {
system("Cls");
first_page();
}
break;
default:
printf("\nInvalid Option Selection!!!");
Sleep(2000);
system("Cls");
Percentage_Calculation();
break;
}
}
}
void Power_Function() {
printf("Welcome To Power(A^n) Calculator\n");
printf("=============================================================\nPress Enter For Operation. Press Esc For Go Back!!!\n");
var = getch();
if(var == 27) {
system("Cls");
first_page();
} else if(var == 13) {
printf("=============================================================\n");
int base, exp;
printf("Enter Base Value : ");
scanf("%d", &base);
printf("Enter Exponent Value : ");
scanf("%d",&exp);
double b = base, e = exp, result = pow(b,e);
int res = (int)result;
printf("Output : %d",res);
printf("\n\nPress Enter Key To Reset, Press Esc To Go Back!!! ");
if(getch() == 13) {
system("Cls");
Power_Function();
} else {
system("Cls");
first_page();
}
}
}
void Root_Function() {
printf("Welcome To Root Of A Number Calculator\n");
printf("=============================================================\nPress Enter For Operation. Press Esc For Go Back!!!\n");
var = getch();
if(var == 27) {
system("Cls");
first_page();
} else if(var == 13) {
printf("=============================================================\n");
int base, root;
printf("Enter Base Value : ");
scanf("%d", &base);
printf("Enter Root Value : ");
scanf("%d",&root);
double r = root;
r = 1/r;
printf("\nOutput : %lf",pow(base,r));
printf("\n\nPress Enter Key To Reset, Press Esc To Go Back!!! ");
if(getch() == 13) {
system("Cls");
Root_Function();
} else {
system("Cls");
first_page();
}
}
}
void Factorial_Function() {
printf("Welcome To Factorial(A!) Of A Number Calculator\n");
printf("=============================================================\nPress Enter For Operation, Press Esc For Go Back. \n");
var = getch();
if(var == 27) {
system("Cls");
first_page();
} else if(var == 13) {
printf("=============================================================\n");
long num, count = 1;
printf("Enter Input Value : ");
scanf("%ld",&num);
for(long i = 1; i <= num; i++) {
count *= i;
}
printf("Output : %ld",count);
printf("\n\nPress Enter Key To Reset, Press Esc To Go Back. ");
if(getch() == 13) {
system("Cls");
Factorial_Function();
} else {
system("Cls");
first_page();
}
}
}
int first_page() {
printf("Press Enter For Move Further. Press Esc for Go back To Main.\n=============================================================\n");
var = getch();
if(var == 13) {
int option;
printf("Enter The Option Value For Enter Into That Operation:\n");
printf("1. Integer Arithmetic Operation\n2. Floating ArithmeticOperation\n3. Percentage Calculation\n4. Power Of A Number\n5. Root Of A Number\n6. Factorial Of A Number");
printf("\n\nChoose An Option : ");
scanf("%d",&option);
switch(option) {
case 1:
system("Cls");
Integer_ArithMetic_Function();
break;
case 2:
system("Cls");
Float_Arithmetic_Function();
break;
case 3:
system("Cls");
Percentage_Calculation();
break;
case 4:
system("Cls");
Power_Function();
break;
case 5:
system("Cls");
Root_Function();
break;
case 6:
system("Cls");
Factorial_Function();
break;
default:
printf("\nInvalid Option!");
Sleep(2000);
system("Cls");
first_page();
break;
}
}
if(var == 27) {
system("cls");
main();
}
}
int main() {
printf("Welcome To Basic Calculator Project In C Programming Language");
printf("\n=============================================================\n");
printf("Created By: Atish Kumar Sahu\nStart Date: 19 - July - 2023\nEnd Date: 20 - July - 2023\n");
printf("=============================================================\n");
printf("Press Enter To Go Next Page!!!");
var = getch();
if(var != 13) {
system("Cls");
main();
} else {
system("Cls");
first_page();
}
getch();
}