forked from ALX-SE-Algorithmia/Demo-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc_func.c
110 lines (100 loc) · 2.08 KB
/
calc_func.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
#include "calc.h"
/**
* two_operand_calc - performs basic calculations on two operands
* @n: first operand
* @m: second operand
* @choice: choice of operation
* Return: void
*/
void two_operand_calc(char *n, char *m, int choice)
{
double a = valid_input(n);
double b = valid_input(m);
double result;
switch (choice)
{
case 1:
result = add(a, b);
printf("%.2lf + %.2lf = %.2lf\n", a, b, result);
break;
case 2:
result = sub(a, b);
printf("%.2lf - %.2lf = %.2lf\n", a, b, result);
break;
case 3:
result = mul(a, b);
printf("%.2lf * %.2lf = %.2lf\n", a, b, result);
break;
case 4:
result = division(a, b);
printf("%.2lf / %.2lf = %.2lf\n", a, b, result);
break;
case 5:
result = mod(a, b);
printf("%.0lf %% %.0lf = %0.lf\n", a, b, result);
break;
default:
break;
}
}
/**
* single_operand_calc - performs basic calculations on one operand
* @n: operand
* @choice: choice of operation
* Return: void
*/
void single_operand_calc(char *n, int choice)
{
double a = valid_input(n);
unsigned long long l_result;
double result;
switch (choice)
{
case 8:
result = logten(a);
printf("log\u2081\u2080(%.2lf) = %.2lf\n", a, result);
break;
case 9:
l_result = factorial((int)(a));
printf("%.0lf! = %llu\n", a, l_result);
break;
case 10:
l_result = fib((int)(a));
printf("Fibonacci of %.0lf = %llu\n", a, l_result);
break;
}
}
/**
* special_calc - performs special calculations
* @choice: choice of operation
* Return: void
*/
void special_calc(int choice)
{
char n[100];
char m[100];
double a, b, result;
switch (choice)
{
case 6:
printf("Enter \u221Aroot: ");
scanf("%s", n);
printf("Enter n\u221A: ");
scanf("%s", m);
a = valid_input(n);
b = valid_input(m);
result = root(a, b);
printf("%.2lf\u221A%.2lf = %.2lf\n", b, a, result);
break;
case 7:
printf("Enter base: ");
scanf("%s", n);
printf("Enter exponent: ");
scanf("%s", m);
a = valid_input(n);
b = valid_input(m);
result = exponent(a, b);
printf("%.2lf ^ %.2lf = %.2lf\n", a, b, result);
break;
}
}