## ~riderius/cpp-code

cpp-code/math_stat.cpp -rw-r--r-- 1.4 KiB
380d65aariderius digits_analysis.cpp: argv[1] can replace n 11 days ago
`                                                                                `
```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```
```#include <cmath>
#include <iostream>

long long fib(long long n);
long long factorial(long long num);

int main(int argc, char* argv[])
{
using namespace std;

const long double Pi = 3.1415926535897932;
float num;

if (argc > 1)
num = atoi(argv[1]);
else {
cout << "Enter a number: ";
cin >> num;
cout << endl;
}

cout << "square " << num * num << endl;
cout << "cube " << num * num * num << endl;
cout << "sqrt " << sqrt(num) << endl;
if (num > -1 && num < 21) {
if (num != 0) {
cout << "fib " << fib(num) << endl;
}
cout << "factorial " << factorial(num) << endl;
}
if (num > -1) {
cout << "area of a circle " << Pi * num * num << endl;
}
cout << "cos " << cos(num) << endl;
cout << "acos " << acos(num) << endl;
cout << "sin " << sin(num) << endl;
cout << "asin " << asin(num) << endl;
cout << "tan " << tan(num) << endl;
cout << "atan " << atan(num) << endl;

return 0;
}

long long fib(long long n)
{
long long fib0 = 0, fib1 = 1, temp, count = 1;
while (count != n) {
temp = fib1;
fib1 = fib0 + fib1;
fib0 = temp;
count++;
}
return fib1;
}

long long factorial(long long n)
{
long long num = 1;
for (int i = 1; i <= n; i++) {
num *= i;
}
return num;
}
```