Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- long double f(long double x)
- {
- return(3*x*x+6*x+1);
- }
- int main() {
- long double a, b, c, d;
- 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)
- {
- c=(a+b)/2;
- if (f(c)==0) {cout << c; return 0;}
- else if (f(a)*f(c)<0) b=c;
- else if (f(b)*f(c)<0) a=c;
- else {cout << "brak"; return 0;}
- cout << a << " " << b << endl;
- }
- cout << endl << "Ostateczne miejsce zerowe: " << c << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement