GGMPL

Miejsca Zerowe

Apr 27th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. double f(double x)
  6. {
  7.     return(3*x*x+6*x+1);
  8. }
  9.  
  10. int main() {
  11.     double d, a, b;
  12.     cin >> a >> b >> d;
  13.     if (f(a)==0) {cout << a; return 0;}
  14.     if (f(b)==0) {cout << b; return 0;}
  15.     while (abs(b-a)>d)
  16.     {
  17.         double c=(a+b)/2;
  18.         if (f(c)==0) {cout << b; return 0;}
  19.         if ((f(a)*f(c))>0) a=c;
  20.         else b=a;
  21.         cout << a << " " << b << endl;
  22.     }
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment