fork(4) download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. double x, eps, left, right, d, s;
  7. cin >> x >> eps;
  8. int n=0;
  9. left=atan(x);
  10. right=x;
  11. d=fabs(left-right);
  12. s=x;
  13. while(d>eps)
  14. {
  15. n++;
  16. s*=(-1)*x*x;
  17. right+=s/(2*n+1);
  18. d=fabs(left-right);
  19. }
  20. cout << "left=" << left << " right=" << right << " n=" << n << " d=" << d;
  21. return 0;
  22. }
Success #stdin #stdout 0s 3432KB
stdin
0.7 0.00000000001
stdout
left=0.610726 right=0.610726 n=28 d=8.34648e-12