69,373
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<math.h>
float fun(float x)
{
return x*x+2*x;
}
int main()
{
float x1,x2,x,precision=1e-2;
while(1){
printf("enter two num:");
scanf("%f %f",&x1,&x2);
if(fun(x1)*fun(x2)<0) break;
}
while(fabs(x1-x2)>precision)
{
printf("there\n");
x=x1-fun(x1)*(x1-x2)/(fun(x1)-fun(x2));
if(fun(x1)*fun(x)>0)
x1=x;
else x2=x;
}
printf("root :%f\n",x);
}