f(mid)与y比较,如果小 l=mid;否则r=mid; 代码: 登录后复制 #include<iostream> #include<cstdio> #include<cmath> using namespace std; const double eps=1e-3; double f(double x){ return pow(x,4)+5*pow(x,3)+6*pow(x,2)+7*x+4; } double cal(double y){ if(f(0)>y||f(100)<y){ return -1; }//零点存在定理 double l=0,r=100; while(r-l>eps){ double mid=(l+r)/2; if(f(mid)>y){ r=mid; } else{ l=mid; } return l; } int main(){ double y; cin>>y; printf("%.3f\n",cal(y)); return 0; } 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29. 原创作者: u_16969274 转载于: https://blog.51cto.com/u_16969274/11813542