Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- float f (float x){
- return (5*x*x*x*x*x-4*x*x*x*x+3*x*x*x-2*x*x+x-1);
- }
- float ff (float x){
- return(pow(2,x)-10);
- }
- float a,b,d;
- int main()
- {
- /* cin >> a >> b >> d;
- if(f(a)==0)
- {
- cout << a<< " "<< f(a); return 0;
- }
- if(f(b)==0)
- {
- cout << b<< " " << f(b); return 0;
- }
- while (b-a>d)
- {
- float sr = (a+b)/2;
- if(f((a+b)/2)==0)
- {
- cout << (a+b)/2 << " "<< f(sr); return 0;
- }
- if(f(a)*f(sr)<0)b=sr;
- else a = sr;
- }
- cout << (a+b)/2<<" " <<f((a+b)/2);
- */
- cin >> a >> b >> d;
- if(f(a)==0)
- {
- cout << a<< " "<< f(a); return 0;
- }
- if(ff(b)==0)
- {
- cout << b<< " " << ff(b); return 0;
- }
- while (b-a>d)
- {
- float sr = (a+b)/2;
- if(ff((a+b)/2)==0)
- {
- cout << (a+b)/2 << " "<< ff(sr); return 0;
- }
- if(ff(a)*ff(sr)<0)b=sr;
- else a = sr;
- }
- cout << (a+b)/2<<" " <<ff((a+b)/2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement