-
Notifications
You must be signed in to change notification settings - Fork 0
/
ComplexCalculator.c
228 lines (196 loc) · 6.15 KB
/
ComplexCalculator.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
#include <stdio.h>
#include <stdbool.h>
#include <math.h>
int gcd();
int basicOperations();
int complexOperations();
int misOperations();
int main(){
int MChoice;
bool isContinue = false;
while (isContinue != true)
{
printf("****************|Enter your choice|****************\n");
printf("\t\t1. Basic Operations\n");
printf("\t\t2. Complex Math Operations\n");
printf("\t\t3. MISCELLANEOUS Operations\n");
printf("\t\t4. Exit\n");
printf("\t\t>>>> ");
scanf("%d",&MChoice);
switch (MChoice)
{
case 1:
printf("****************|Basic Operations|****************\n");
basicOperations();
continue;
case 2:
printf("****************|Complex Math Operations|****************\n");
complexOperations();
continue;
case 3:
printf("****************|MISCELLANEOUS Operations|****************\n");
misOperations();
continue;
case 4:
printf("****************|Thank You For Using|****************\n");
isContinue = true;
break;
default:
printf("\t\tYou Have to enter the proper option.\n");
printf("\t\tpress 1 for Basic Operations\n");
printf("\t\tpress 2 for Complex Math Operations\n");
printf("\t\tpress 3 for MISCELLANEOUS Operations\n");
printf("\t\tpress 4 to EXIT from the program\n");
break;
}
}
return 0;
}
int basicOperations(){
char operation;
float num1,num2;
printf("\t\t'+' for Addition\n");
printf("\t\t'-' for Substraction\n");
printf("\t\t'*' for Multiplication\n");
printf("\t\t'/' for Division\n");
printf("\t\t>>>> ");
scanf("%s",&operation);
printf("\t\tEnter the number: \n");
printf("\t\t>>>> ");
scanf("%f",&num1);
printf("\t\tEnter the number: \n");
printf("\t\t>>>> ");
scanf("%f",&num2);
switch (operation)
{
case '+':
printf("\t\tThe sum of %.2f and %.2f is %.2f\n",num1,num2,(num1+num2));
break;
case '-':
printf("\t\tThe difference of %.2f and %.2f is %.2f\n",num1,num2,(num1-num2));
break;
case '*':
printf("\t\tThe product of %.2f and %.2f is %.2f\n",num1,num2,(num1*num2));
break;
case '/':
if (num2 == 0)
{
printf("\t\tZero division Error\n");
}
else
{
printf("\t\tThe division of %.2f and %.2f is %.2f\n",num1,num2,(num1/num2));
}
break;
default:
printf("\t\tentered operation is invalid\n");
break;
}
return 0;
}
int complexOperations()
{
int complexChoice;
float number;
printf("\t\t1. Square\n");
printf("\t\t2. Cube\n");
printf("\t\t3. Square Root\n");
printf("\t\t>>>> ");
scanf("%d",&complexChoice);
switch (complexChoice){
case 1:
printf("\t\tEnter the number: \n");
printf("\t\t>>>> ");
scanf("%f",&number);
printf("\t\t%f\n",number*number);
break;
case 2:
printf("\t\tEnter the number: \n");
printf("\t\t>>>> ");
scanf("%f",&number);
printf("\t\t%f\n",number*number*number);
break;
case 3:
printf("\t\tEnter the number: \n");
printf("\t\t>>>> ");
scanf("%f",&number);
printf("\t\t%f\n",sqrt(number));
break;
default:
printf("\t\tYou Have to enter the proper option.\n");
printf("\t\tpress 1 for Sqaure\n");
printf("\t\tpress 2 for Cube \n");
printf("\t\tpress 3 for Square Root\n");
break;
}
}
int misOperations(){
int misChoice,number,num1,num2,res;
printf("\t\t1. Remainder\n");
printf("\t\t2. GCD and LCM\n");
printf("\t\t3. Odd or Even\n");
printf("\t\t>>>> ");
scanf("%d",&misChoice);
switch (misChoice){
case 1:
printf("\t\tEnter the number: \n");
printf("\t\t>>>> ");
scanf("%d",&num1);
printf("\t\tEnter the number: \n");
printf("\t\t>>>> ");
scanf("%d",&num2);
res = num1%num2;
printf("\t\t%d\n",res);
break;
case 2:
gcd();
break;
case 3:
printf("\t\tEnter the number: \n");
printf("\t\t>>>> ");
scanf("%d",&number);
if (number%2==0)
{
printf("\t\t%d is Even Number\n",number);
}
else
{
printf("\t\t%d is Odd Number\n",number);
}
break;
default:
printf("\t\tYou Have to enter the proper option.\n");
printf("\t\tpress 1 for Sqaure\n");
printf("\t\tpress 2 for Cube \n");
printf("\t\tpress 3 for Square Root\n");
break;
}
}
int gcd(){
int num1,num2,gcd,lcm,rem,nume,den;
printf("\t\tEnter the number: \n");
printf("\t\t>>>> ");
scanf("%d",&num1);
printf("\t\tEnter the number: \n");
printf("\t\t>>>> ");
scanf("%d",&num2);
nume = (num1>num2)?num1:num2;
//here we define largest number as numerator
den = (num1>num2)?num2:num1;
//here we define smallest number as a denominator
rem = nume%den;
// we calculate the reminder of numerator and denominator to run a loop
while (rem!=0)
{
nume=den;
den=rem;
rem=nume%den;
// we run this loopby interchanging the values untill rem is 0
}
gcd = den;
// final denominator is assigned to gcd
lcm = (num1*num2)/gcd;
// lcm formula is (num1*num2)/gcd.
printf("\t\tGCD of the given numbers is: %d\n",gcd);
printf("\t\tLCM of the given numbers is: %d\n", lcm);
}