Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. double f(double x)
  8. {
  9. return sin(x)-x*x;
  10. }
  11.  
  12. int main()
  13. {
  14. double eps = 0.0000001;
  15. double a, b, c;
  16. cin >> a >> b;
  17. if (f(a)==0)
  18. cout << a << endl;
  19. if (f(b)==0)
  20. cout << b << endl;
  21. while(fabs(a-b)>eps)
  22. {
  23. c = (a+b)/2.0;
  24. if (f(c)==0)
  25. {
  26. cout << c << endl;
  27. break;
  28. }
  29. if (f(a)*f(c)<0)
  30. b = c;
  31. else
  32. a = c;
  33. }
  34. cout.precision(10);
  35. cout << fixed << c << endl;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement