jaredec18

Untitled

Sep 28th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. https://media.cheggcdn.com/media/8c6/8c6d06da-aa61-4c53-9ff6-aeb760d1335d/php3yrHXa.png
  2.  
  3. #include <iostream>
  4. #include <cmath>
  5. #include <iomanip>
  6.  
  7. using namespace std;
  8.  
  9. double piValue() {
  10. double p = 1;
  11. int i = 1;
  12.  
  13. while(true) {
  14. double prev = p;
  15. p += pow(-1, i) * (1.0 / (1 + 2*i));
  16.  
  17. if(abs(prev - p) < 0.00005) {
  18. break;
  19. }
  20. i++;
  21. }
  22.  
  23. return 4*p;
  24. }
  25.  
  26. int main() {
  27. cout << piValue() << endl;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment