Tvor0zhok

Рекурсия IV

Feb 17th, 2021
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. float F (float x, float a, float b)
  5. {
  6. if (x*x - 5*x < 0) return a + b;
  7. else if (x*x - 5*x >= 10) return a * b;
  8. else return a - b;
  9. }
  10.  
  11. void F (float x, float a, float b, float &y)
  12. {
  13. if (x*x - 5*x < 0) y = a + b;
  14. else if (x*x - 5*x >= 10) y = a * b;
  15. else y = a - b;
  16. }
  17.  
  18. int main()
  19. {
  20. float a, b, h;
  21. cout << "a = "; cin >> a;
  22. cout << "b = "; cin >> b;
  23. cout << "h = "; cin >> h;
  24.  
  25. //float F
  26. cout << "float F\n";
  27. cout << "x\tf(x)\n";
  28. for (float x = a; x <= b; x += h)
  29. cout << x << '\t' << F(x, a, b) << '\n';
  30.  
  31. //void F
  32. cout << "void F\n";
  33. cout << "x\tf(x)\n";
  34. for (float x = a; x <= b; x += h)
  35. {
  36. float y; F(x, a, b, y);
  37. cout << x << '\t' << y << '\n';
  38. }
  39.  
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment