-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmathcli.h
More file actions
166 lines (117 loc) · 3.32 KB
/
mathcli.h
File metadata and controls
166 lines (117 loc) · 3.32 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
#include <stdio.h>
#include "mathtools.h"
void template(){
unsigned long long n;
printf("\n---Tool Name---\n");
printf("Description of tool.\n");
while(true){
printf("\nEnter a valid number or 0 to terminate: ");
scanf("%lli", &n);
if(!n){
break;
}
}
printf("\n---Terminated---\n");
return;
}
void call_prime_checker(){
unsigned long long n;
printf("\n---Prime Checker---\n");
printf("Checks if a natural number (ℕ), is prime.\n");
while(true){
printf("\nEnter a natural number (ℕ) or 0 to terminate: ");
scanf("%lli", &n);
if(!n){
break;
}
if(is_prime(n)){
printf("\n%lli is a prime number.\n", n);
}
else{
printf("\n%lli is not a prime number.\n", n);
}
}
printf("\n---Terminated---\n");
return;
}
void call_prime_list(){
unsigned long long a, b, tally;
printf("\n---Prime Number List---\n");
printf("Finds all prime numbers in the set [a, b], such that a, and b, are natural numbers (ℕ).\n");
while(true){
printf("\nEnter a range of natural numbers (ℕ), [a, b], or zero for both values to terminate.\n\n");
printf("Enter a: ");
scanf(" %lli", &a);
printf("Enter b: ");
scanf(" %lli", &b);
if(!a && !b){
break;
}
list_primes(a, b, &tally);
printf("\nThere are %lli primes within [%lli, %lli].\n", tally, a, b);
}
printf("\n---Terminated---\n");
return;
}
void call_solve_quadratic(){
double a, b, c, t1, t2;
bool imaginary;
printf("\n---Quadratic Solver---\n");
printf("Solves a quadratic of the form ax^2 + bx + c = 0, such that all variables are real numbers (ℝ).\n");
while(true){
printf("\nEnter a (or 0 to terminate): ");
scanf("%lf", &a);
if(!a){
break;
}
printf("Enter b: ");
scanf("%lf", &b);
printf("Enter c: ");
scanf("%lf", &c);
solve_quadratic(a, b, c, &t1, &t2, &imaginary);
if(imaginary){
printf("\nx = %.6g ± %.6gi\n", t1, t2);
}
else{
printf("\nx1 = %.6g\nx2 = %.6g\n", t1 + t2, t1 - t2);
}
}
printf("\n---Terminated---\n");
return;
}
void call_factoriser(){
unsigned long long n, num_factors;
printf("\n---Factoriser---\n");
printf("Lists all positive factors of a natural number (ℕ).\n");
while(true){
printf("\nEnter a natural number (ℕ) or 0 to terminate: ");
scanf("%lli", &n);
if(!n){
break;
}
factorise(n, &num_factors);
printf("\n%lli has %lli factors.\n", n, num_factors);
}
printf("\n---Terminated---\n");
return;
}
void call_prime_factoriser(){
unsigned long long n;
printf("\n---Prime Factoriser---\n");
printf("Lists prime factors of a natural number (ℕ).\n");
while(true){
printf("\nEnter a natural number (ℕ) or 0 to terminate: ");
scanf("%lli", &n);
if(!n){
break;
}
if(n == 1){
printf("\n1 has no prime factors.\n");
}
else{
prime_factorise(n);
}
}
printf("\n---Terminated---\n");
return;
}