-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.cpp
55 lines (42 loc) · 1002 Bytes
/
functions.cpp
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
#include "functions.hpp"
double Sqrt(double x) {
return sqrt(x);
}
double Pow(double base, double exponant) {
return pow(base, exponant);
}
unsigned long Factorial(unsigned char n) {
return ((n == 0) ? 1 : n * Factorial(n - 1));
}
unsigned int FrequencyOfPrimes(unsigned int n) {
unsigned int j;
unsigned int freq = n - 1;
for (unsigned int i = 2; i <= n; ++i) {
for (j = Sqrt(i); j > 1; --j) {
if (i % j == 0) {
--freq;
break;
}
}
}
return freq;
}
double Madhava(unsigned int n) {
double result = 0.0;
const double oneThird = -(1.0/3.0);
for (unsigned int i = 0; i < n; ++i) {
result += (Pow(oneThird, i) / (2.0 * i + 1.0));
}
result *= Sqrt(12);
return result;
}
unsigned int AskMax(const std::string & sentence) {
unsigned int max;
std::cout << sentence;
std::cin >> max;
if (max < 2) {
std::cout << "Forcing to 2" << std::endl;
max = 2;
}
return max;
}