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 t = 1, s = 1;
  10. for(int k = 1; abs(t) > eps; ++k)
  11. s += t *= x*(3-2*k)/(2*k);
  12. return s;
  13. }
  14.  
  15. int main(int argc, char * argv[])
  16. {
  17. for(double x = 0; x < 1; x += 0.1)
  18. {
  19. cout << setprecision(3) << setw(5) << x
  20. << setprecision(8) << setw(10) << sqrt(1+x) << " "
  21. << setprecision(8) << setw(10) << series(x,1e-8) << endl;
  22.  
  23. }
  24. }
  25.  
Success #stdin #stdout 0.01s 5536KB
stdin
Standard input is empty
stdout
    0         1            1
  0.1 1.0488088    1.0488088
  0.2 1.0954451    1.0954451
  0.3 1.1401754    1.1401754
  0.4  1.183216     1.183216
  0.5 1.2247449    1.2247449
  0.6 1.2649111    1.2649111
  0.7 1.3038405    1.3038405
  0.8 1.3416408    1.3416408
  0.9 1.3784049    1.3784049
    1 1.4142136    1.4142136