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(3*x*x+6*x+1);
- }
- int main() {
- double d, a, b;
- cin >> a >> b >> d;
- if (f(a)==0) {cout << a; return 0;}
- if (f(b)==0) {cout << b; return 0;}
- while (abs(b-a)>d)
- {
- double c=(a+b)/2;
- if (f(c)==0) {cout << b; return 0;}
- if ((f(a)*f(c))>0) a=c;
- else b=a;
- cout << a << " " << b << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment