fork(1) download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. double s(double x, double eps = 1e-10)
  8. {
  9. double a = x*x*x;
  10. x = x*x;
  11. double sum = a/3.0;
  12. for(int k = 2; fabs(a) >= 4*eps*k*k; ++k)
  13. {
  14. sum += (a*=-x)/(4.0*k*k-1);
  15. }
  16. return sum;
  17. }
  18.  
  19.  
  20.  
  21. int main(int argc, const char * argv[])
  22. {
  23. for(double x = 0.1; x <= 1.0; x += 0.1)
  24. {
  25. cout << setw(4) << x << setw(12)
  26. << ((1+x*x)*atan(x)-x)/2.0
  27. << setw(12) << s(x) << endl;
  28. }
  29. }
  30.  
  31.  
  32.  
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
 0.1  0.00033267  0.00033267
 0.2  0.00264569  0.00264569
 0.3  0.00884395  0.00884395
 0.4   0.0206937   0.0206937
 0.5   0.0397798   0.0397798
 0.6   0.0674853   0.0674853
 0.7    0.104991    0.104991
 0.8    0.153288    0.153288
 0.9    0.213198    0.213198
   1    0.285398    0.285398