fork download
  1. #include <cmath>
  2. #include <iostream>
  3. #include <iomanip>
  4.  
  5. double calcPi(double precision){
  6. double PI = 1.0, temp;
  7.  
  8. for(double i = 0.0; i < precision; i++){
  9. temp = 1.0;
  10. temp /= (3 + i * 2) * pow(3, i + 1);
  11. PI += (int(i) % 2 == 0)? -temp : temp;
  12. }
  13. return sqrt(12) * PI;
  14. }
  15.  
  16. int main() {
  17. std::cout << std::setprecision(500) << calcPi(50000) << std::endl;
  18. return 0;
  19. }
Success #stdin #stdout 0.01s 3296KB
stdin
Standard input is empty
stdout
3.141592653589793560087173318606801331043243408203125