
#include
#include
double f(double x)
{
return x*x*x*x*x-3*x+1; //方程
}
void main()
{
double e=1e-3; //精确值
double start,end,mid;
cout<<"输入二分法的起始最小值和最大值"<
cin>>end;
while(f(start)*f(end)>0)
{
cout<<"f(start)*f(end)必须小于0!请重新输入二分法的起始最小值和最大值"<
cin>>end;
}
if(fabs(f(start))<=e)
{cout<<"求出的值为x="<
{cout<<"求出的值为x="<
{
mid=(start+end)/2;
while(fabs(f(mid))>e)
{
if(f(start)*f(mid)<0)
{
end=mid;
}
else
{
start=mid;
}
mid=(start+end)/2;
}
cout<<"求出的值为x="<
}
ps:运行程序,输入起始值0和1,求出了x=0.334961