Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1.  
  2. #include "pch.h"
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. double Func(double x) {
  7. //Здесь должны написать функцию, которую она дала...
  8.  
  9. //Я напишу просто возврат значения х
  10. return x;
  11. }
  12.  
  13.  
  14. int main()
  15. {
  16. double y, eps;
  17. int n;
  18. double x1, x2, xt;
  19. cout << "Enter y:";
  20. cin >> y;
  21. cout << endl;
  22. cout << "Enter eps:";
  23. cin >> eps;
  24. cout << endl;
  25. cout << "Enter n:";
  26. cin >> n;
  27. cout << endl;
  28. system("cls");
  29. x1 = 1;
  30. while (Func(x1) > y) {
  31. x1 /= 2;//x1=x1/2; одно и то же
  32. };
  33. x2 = 1;
  34. while (Func(x2) < y) {
  35. x2 *= 2;//x2=x2*2
  36. };
  37. while ((x2 - x1) > eps) {
  38. xt = (x1 + x2) / 2;
  39. if (Func(xt) > y) {
  40. x2 = xt;
  41. }
  42. else {
  43. x1 = xt;
  44. };
  45. };
  46. cout << "xt=" << xt << endl;
  47. cout << "y=" << y<<endl;
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement