Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://media.cheggcdn.com/media/8c6/8c6d06da-aa61-4c53-9ff6-aeb760d1335d/php3yrHXa.png
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- double piValue() {
- double p = 1;
- int i = 1;
- while(true) {
- double prev = p;
- p += pow(-1, i) * (1.0 / (1 + 2*i));
- if(abs(prev - p) < 0.00005) {
- break;
- }
- i++;
- }
- return 4*p;
- }
- int main() {
- cout << piValue() << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment