#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>
using namespace std;
double f(double x)
{
return (x*x*x-3*x*x+3*x-1);
}
double erfen(double x1,double x2,double (*p)(double))//double (*p)(double)为形参,相当于函数别名
{
double xx;
do
{
xx=(x1+x2)/2;
if((*p)(xx)*(*p)(x1)>0)
x1=xx;
else
x2=xx;
}while(fabs((*p)(xx))>=1e-7);//le-7代表1*10的-6次方,它的值将影响到跟的准确度的问题
return xx;
}
int main()
{
double x1,x2;
double f(double);
double (*p)(double);
p=f;
do
{
scanf("%lf%lf",&x1,&x2);
}
while((*p)(x1)*(*p)(x2)>0);//保证f(x1)和f(x2)是异号,这样才可以进行下一步的精准区间,否则,重新输入x1,x2的值
printf("%.2lf\n",erfen(x1,x2,f));
return 0;
}