#include<iostream>
using namespace std;
float f(float x)
{ return x*x*x+x-1;
}
float DEI(float s, float d)
{
if(d-s<=0.0001) return s;
else
{ float m=(s+d)/2;
if(f(m)==0) return m;
else if(f(m)<0) return DEI(m,d);
else return DEI(s,m);
}
}
int main()
{ cout<<DEI(0,1);
system("pause");
return 0;
}
|