Advertisement
Victorskiee

Untitled

Apr 27th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. long double f(long double x)
  6. {
  7. return(3*x*x+6*x+1);
  8. }
  9.  
  10. int main() {
  11. long double a, b, c, d;
  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. c=(a+b)/2;
  18. if (f(c)==0) {cout << c; return 0;}
  19. else if (f(a)*f(c)<0) b=c;
  20. else if (f(b)*f(c)<0) a=c;
  21. else {cout << "brak"; return 0;}
  22. cout << a << " " << b << endl;
  23. }
  24. cout << endl << "Ostateczne miejsce zerowe: " << c << endl;
  25. return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement