Bob103

Сааам сделал

Nov 30th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3. #include<iomanip>
  4. using namespace std;
  5. float fun(float x, float e, int &n)
  6. {
  7. float s = 0, a = (x - 1);
  8. n = 0;
  9. while (fabs(a)>=e)
  10. {
  11. s += a;
  12. a *= -pow(x - 1, 2) / 2;
  13. n++;
  14. }
  15. return s;
  16. }
  17. int main()
  18. {
  19. float a, b, e, h, f, x;
  20. cout << "a="; cin >> a;
  21. cout << "b="; cin >> b;
  22. cout << "e="; cin >> e;
  23. cout << "h="; cin >> h;
  24. int n, i;
  25. cout << setprecision(3);
  26. cout << "i\t x\t f(x)\t n\n";
  27. for (x = a, i = 2; x <= b; x += h, i++)
  28. {
  29. f = fun(x, e, n);
  30. cout << i << "\t" << x << "\t" << f << "\t" << n << endl;
  31. }
  32. system("pause");
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment