Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- double f(double x)
- {
- return sin(x)-x*x;
- }
- int main()
- {
- double eps = 0.0000001;
- double a, b, c;
- cin >> a >> b;
- if (f(a)==0)
- cout << a << endl;
- if (f(b)==0)
- cout << b << endl;
- while(fabs(a-b)>eps)
- {
- c = (a+b)/2.0;
- if (f(c)==0)
- {
- cout << c << endl;
- break;
- }
- if (f(a)*f(c)<0)
- b = c;
- else
- a = c;
- }
- cout.precision(10);
- cout << fixed << c << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement