Seal_of_approval

p61

Nov 24th, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <cmath>
  2. #include <iostream>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. double f (double x, double eps, int& n)
  7. {
  8. double step = 1;
  9. double s = 0;
  10. int k=1;
  11. int fact=1;
  12. int t = -1;
  13. while (fabs(step)>=eps)
  14. {
  15. s += step;
  16. fact *= (2*k+2)*(2*k+3);
  17. step *= t*x*x/fact;
  18. n ++;
  19. k ++;
  20. t = -t;
  21. }
  22. return s;
  23. }
  24.  
  25. int main (void)
  26. {
  27. double eps;
  28. double a = 0.0;
  29. const double b = 1.0;
  30. const double h = 0.1;
  31. cin >> eps;
  32. int i = 1;
  33. cout << "No\t x \t F(x) \t count\n";
  34. for (; a<= b; a += h)
  35. {
  36. int n = 0;
  37. double fx = f(a, eps, n);
  38. cout <<setw(3) << i << " \t" << setw(5) << a << "\t" << setw(10) << fx << "\t" << n << endl;
  39. i++;
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment