作者:yunjinqi 类别:
日期:2023-05-29 13:44:57
阅读:464 次 消耗积分:0 分
#include <stdio.h>
double fv(double a3,double a2,double a1,double a0,double x){
double value = a3*x*x*x + a2*x*x + a1*x + a0;
return value;
}
double solve_equation(double a3,double a2,double a1,double a0,double a,double b){
double mid;
double fa,fb,fm;
fa = fv(a3,a2,a1,a0,a);
fb = fv(a3,a2,a1,a0,b);
if (fa==0){return a;}
if (fb==0){return b;}
while (fa*fb<0){
fa = fv(a3,a2,a1,a0,a);
fb = fv(a3,a2,a1,a0,b);
mid = (a+b)/2;
fm = fv(a3,a2,a1,a0,mid);
//printf("%lf %lf %lf %lf %lf\n",a,b,fa,fb,fm);
if (fm<=0.0001 && fm>=-0.0001){return mid;}
else{
if (fm*fb<0){a=mid;}
if (fm*fa<0){b=mid;}
}
}
while (fa*fb>0){return 9999999;}
}
int main(){
double a3,a2,a1,a0,a,b;
if (scanf("%lf %lf %lf %lf %lf %lf",&a3,&a2,&a1,&a0,&a,&b)!=0){
//printf("%lf %lf %lf %lf %lf %lf\n",a3,a2,a1,a0,a,b);
double r;
r = solve_equation(a3,a2,a1,a0,a,b);
printf("%.2lf",r);
}else{
printf("something wrong");
}
return 0;
}