fork(2) download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. double b = 1, a = 0.1, eps = 0.00000001;
  9.  
  10. for(double x = a; x <= b; x += (b-a)/10)
  11. {
  12. double t = 1, s = 0;
  13. for(int n = 0; abs(t) > eps; ++n)
  14. s += t *= -2*x*x/(2*n+1)/(n+1);
  15. double c = cos(x);
  16.  
  17. cout << "x: " << setw(15) << x;
  18. cout << " y(x): " << setw(15) << 2*(c*c-1);
  19. cout << " s(x): " << s << endl;
  20. }
  21. }
  22.  
Success #stdin #stdout 0.01s 5556KB
stdin
Standard input is empty
stdout
x:             0.1       y(x):      -0.0199334       s(x): -0.0199334
x:            0.19       y(x):      -0.0713354       s(x): -0.0713354
x:            0.28       y(x):       -0.152745       s(x): -0.152745
x:            0.37       y(x):       -0.261531       s(x): -0.261531
x:            0.46       y(x):        -0.39418       s(x): -0.39418
x:            0.55       y(x):       -0.546404       s(x): -0.546404
x:            0.64       y(x):       -0.713285       s(x): -0.713285
x:            0.73       y(x):        -0.88943       s(x): -0.88943
x:            0.82       y(x):        -1.06915       s(x): -1.06915
x:            0.91       y(x):        -1.24663       s(x): -1.24663
x:               1       y(x):        -1.41615       s(x): -1.41615