fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. double pi = 3.14159265358;
  8.  
  9. double Paul(double x, double eps)
  10. {
  11. double y = 1, summa = 0, last = 1;;
  12. for (; fabs(last) > eps;)
  13. {
  14. last = pow(-1, y) * pow(x, 2 * y - 1) / (2 * y - 1);
  15. summa += last;
  16. y+=1;
  17. }
  18. return pi/2 + summa;
  19. }
  20.  
  21. double Harry(double x, double eps)
  22. {
  23. double summ = pi/2 - x, x2n_1 = -x;
  24. x *= x;
  25.  
  26. for(int k = 3; fabs(x2n_1/k) > eps; k += 2)
  27. {
  28. x2n_1 *= -x;
  29. summ += x2n_1/k;
  30. }
  31. return summ;
  32. }
  33.  
  34. int main()
  35. {
  36. for(double x = 0; x <= 0.9; x += 0.1)
  37. {
  38. cout << setw(4) << x
  39. << setw(12) << pi/2-atan(x)
  40. << setw(12) << Paul(x, 1e-10)
  41. << setw(12) << Harry(x, 1e-10) << endl;
  42. }
  43.  
  44.  
  45. }
  46.  
Success #stdin #stdout 0s 4476KB
stdin
Standard input is empty
stdout
   0      1.5708      1.5708      1.5708
 0.1     1.47113     1.47113     1.47113
 0.2      1.3734      1.3734      1.3734
 0.3     1.27934     1.27934     1.27934
 0.4     1.19029     1.19029     1.19029
 0.5     1.10715     1.10715     1.10715
 0.6     1.03038     1.03038     1.03038
 0.7     0.96007     0.96007     0.96007
 0.8    0.896055    0.896055    0.896055
 0.9    0.837981    0.837981    0.837981