#include <stdio.h> #include <iostream> using namespace std; double f(double x) { return x*x*x-x-1; } double func(double a,double b,int n) { double c; int i=0; while(i<n) { c=(a+b)/2; if(f(c)==0) return c; if(f(c)*f(a)>0) a=c; else b=c; i++; } return c; } int main() { double a,b; cout<<"Please input the value a:"<<endl; cin>>a; cout<<"Please input the value b:"<<endl; cin>>b; int n=1000; if(f(a)*f(b)> 0 ) cout<<"No result !"<<endl; if(f(a)==0) cout<<a<<endl; else if(f(b)==0) cout<<b<<endl; cout<<"The result of x value: /n"; else cout<<func(a,b,n)<<endl; char c; cin>>c; return 0; }