fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <limits>
  4. #include <math.h>
  5.  
  6. int main(){
  7. double PI = 0;
  8. double Delta = std::numeric_limits<double>::epsilon() * 2;
  9. double k = 0;
  10.  
  11. while (Delta > std::numeric_limits<double>::epsilon()){
  12. Delta = (4 / (8 * k + 1) - 1 / (4 * k + 2) - 1 / (8 * k + 5) - 1 / (8 * k + 6)) / pow(16.0 ,k);
  13. PI += Delta;
  14. k++;
  15. }
  16.  
  17. std::cout << std::setprecision(16) << "PI => " << PI << " k => " << k << std::endl;
  18.  
  19. return 0;
  20.  
  21. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
PI => 3.141592653589793 k => 12