-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cpp
More file actions
27 lines (22 loc) · 509 Bytes
/
main.cpp
File metadata and controls
27 lines (22 loc) · 509 Bytes
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
#include <iostream>
#include <cstdlib>
#include <iomanip>
int
main(int argc, char* argv[])
{
long long iterations = 1000000;
if (argc > 1) {
iterations = std::atoll(argv[1]);
}
double sum = 0.0;
for (long long i = 0; i < iterations; ++i) {
double term = 1.0 / (2.0 * i + 1.0);
if (i % 2 == 0)
sum += term;
else
sum -= term;
}
double pi = 4.0 * sum;
std::cout << std::setprecision(15);
std::cout << pi << "\n";
}