fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. double Series(double x, double eps)
  8. {
  9. double term = x*x*x/6, sum = term;
  10. x = x*x;
  11. for(int n = 2; abs(term) > eps; ++n)
  12. sum += term *= -x/(2*n*(2*n+1));
  13. return sum;
  14. }
  15.  
  16. int main()
  17. {
  18. for(double x = 0; x < 1; x += 0.1)
  19. cout << setw(5) << x << setw(12) << x-sin(x) << setw(12) << Series(x,1e-7) << endl;
  20. }
  21.  
Success #stdin #stdout 0s 4324KB
stdin
Standard input is empty
stdout
    0           0           0
  0.1 0.000166583 0.000166583
  0.2  0.00133067  0.00133067
  0.3  0.00447979  0.00447979
  0.4   0.0105817   0.0105817
  0.5   0.0205745   0.0205745
  0.6   0.0353575   0.0353575
  0.7   0.0557823   0.0557823
  0.8   0.0826439   0.0826439
  0.9    0.116673    0.116673
    1    0.158529    0.158529