-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelp.c
More file actions
250 lines (212 loc) · 7.42 KB
/
Copy pathhelp.c
File metadata and controls
250 lines (212 loc) · 7.42 KB
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
#include "help.h"
#include<stdio.h>
#include<stdbool.h>
#include<math.h>
#define PI 3.14159
//intro function
void intro(){
printf("\n=================================================\n");
printf("Welcome to the Arithmetic Calculator!\n");
printf("You can perform operations many operations\n");
printf("===================================================\n\n");
}
//for menu
void showMenu() {
printf("\n--- Arithmetic Calculator Menu---\n");
printf("1. Addition (+)\n");
printf("2. Subtraction (-)\n");
printf("3. Multiplication (*)\n");
printf("4. Division (/)\n");
printf("5. Modulo division(%%)\n");
printf("6. Power (^)\n");
printf("7. Square Root (sqrt)\n");
printf("8. Sine (sin)\n");
printf("9. Cosine (cos)\n");
printf("10. Tangent (tan)\n");
printf("11. Arcsin (arcsin)\n");
printf("12. Arccos (arccos)\n");
printf("13. Arctan (arctan)\n");
printf("14. Logarithm (log10)\n");
printf("15. Factorial (!)\n");
printf("Enter your choice (1-15): ");
}
// value conversion
void radianTodegree(double *angle){
*angle = *angle * (180 / PI);
}
void degreeToradian(double *angle){
*angle = *angle * (PI/180);
}
// for input1
void takeinput1(double *number1){
// first number
while(true){
printf("Enter first number: ");
if((scanf("%lf", number1)) != 1){
printf("Invalid number!\n");
}else{
break; // break loop and move ahead;
}
}
}
// taking input2
void takeinput2(double *number2){
//sescond number
while(true){
printf("Enter second number: ");
if((scanf("%lf", number2)) != 1){
printf("Invalid number!\n");
}else{
break; // break loop and move ahead;
}
}
}
// taking angle
void inputangle(double *angle){
//angle
while(true){
printf("Enter angle in degree: ");
if((scanf("%lf", angle)) != 1){
printf("Invalid input!\n");
}else{
break; // break loop and move ahead;
}
}
// converting value in radian
degreeToradian(angle);
}
// for single value
void Single_value(double *value){
//single number
while(true){
printf("Enter value: ");
if((scanf("%lf", value)) != 1){
printf("Invalid value!\n");
}else{
break; // break loop and move ahead;
}
}
}
// addition function
double addition(double a, double b) {
return a + b;
}
// subtraction function
double subtraction(double a, double b) {
return a - b;
}
// multiplication function
double multiplication(double a, double b) {
return a * b;
}
// division function
void division(double a, double b) {
if (b != 0) {
printf("%.2lf / %.2lf= %.2lf\n", a, b, a / b);
} else {
printf("\nError! Division by zero.\n");
return; //
}
}
// modulo function
void modulo(int a, int b) {
if (b != 0) {
printf(" %d %% %d = %d\n", a, b, (a % b));
} else {
printf("\nError! Division by zero.\n");
}
}
// power function
double power(double base, double exponent) {
return pow(base, exponent);
}
// square root function
void square_root(double num) {
if (num >= 0) {
// it take only one value
printf(" Square root of %0.2lf = %.2lf\n", num, sqrt(num));
} else {
printf("Error! Cannot compute square root of a negative number.\n");
// return 0; // Return 0 or handle as needed
}
}
// factorial function - using unsigned long long to handle larger factorials, but keep in mind it can still overflow for n > 20
void factorial(int n) {
if (n < 0) {
printf("Error! Factorial is not defined for negative numbers.");
// return 0; // Return 1 or handle as needed
} else if (n == 0 || n == 1) {
printf(" Factorial of %d = %d\n", n, 1); // Print as integer since factorial is an integer
return ;
} else {
unsigned long long result = 1;
int t = n;
while(t>0){
result *= t;
t--;
}
printf(" Factorial of %d = %llu\n", n, result); // Print as integer since factorial is an integer
// fact_result = 0; // Reset factorial result for next calculation
result = 1;
}
}
// logarithm function
void logarithm(double num) {
if (num > 0) {
printf(" Logarithm(10) of %0.2lf = %.2lf\n", num , log10(num));
return ; // this will calculate the logarithm of number to the base 10
} else {
printf("Error! Logarithm is not defined for non-positive numbers.");
return; // Return 0 or handle as needed
}
}
// trigonometric functions
void sine(double angle) {
double result = sin(angle);
radianTodegree(&angle);
printf(" Sine of %0.2lf = %.2lf\n", angle, result);
return;
}
void cosine(double angle) {
double result = cos(angle);
radianTodegree(&angle);
printf(" cos of %0.2lf = %.2lf\n", angle, result);
return;
}
void tangent(double angle) {
double result = tan(angle);
radianTodegree(&angle);
printf(" tan of %0.2lf = %.2lf\n", angle, result);
return;
}
// inverse trigonometric functions
void arcsine(double value) {
if (value >= -1 && value <= 1) {
printf(" Arcsine of %0.2lf = %.2lf\n", value, asin(value));
return ;
} else {
printf("Error! Arcsine is not defined for values outside the range [-1, 1].");
// return 0; // Return 0 or handle as needed
}
}
void arccosine(double value) {
if (value >= -1 && value <= 1) {
printf(" Arc cosine of %0.2lf = %.2lf\n", value, acos(value));
return ;
} else {
printf("Error! Arccosine is not defined for values outside the range [-1, 1].");
// return 0; // Return 0 or handle as needed
}
}
void arctangent(double value) {
printf(" Arc tangent of %0.2lf = %.2lf\n", value, atan(value));
return ;
}
// result display function
void printResult(double num1, double num2, double result, char operator){
if(result == (long long)result){
printf(" %.2lf %c %.2lf = %lld\n", num1, operator, num2, (long long)result);
}else{
printf(" %.2lf %c %.2lf = %.2lf\n", num1, operator, num2, result);
}
}