fork download
  1. #include <iomanip>
  2. #include <cstdlib>
  3. #include <iostream>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. int main(void)
  9. {
  10. int i;
  11. long double result;
  12. long double pi;
  13. int y=3;
  14. int loopcount=0;
  15. long double precision = 0;
  16. long double previous = 0;
  17.  
  18. cout<<"Start\n";
  19.  
  20. result=1-(pow(1,y)/y);
  21.  
  22. do
  23. {
  24. y=y+2;
  25. result=result+(pow(1,y)/y);
  26. y=y+2;
  27. result=result-(pow(1,y)/y);
  28.  
  29. pi=4*(result);
  30. precision=(pi*(pow(10,11))/10);
  31.  
  32. loopcount++;
  33.  
  34. if (floor(precision)==floor(previous))
  35. break;
  36.  
  37. previous = precision;
  38. }
  39. while(true); //This is the problem!);
  40.  
  41. cout<<"Final Arctan is:"<<endl;
  42. cout<<setprecision(20)<<result<<endl;
  43. cout<<"Final Pi is:"<<endl;
  44. cout<<setprecision(9)<<pi<<endl;
  45. cout<<"Times looped:"<<endl;
  46. cout<<loopcount<<endl;
  47.  
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
Start
Final Arctan is:
0.78539640052495345225
Final Pi is:
3.1415856
Times looped:
70906