提交时间:2023-12-01 20:37:00

运行 ID: 32546

#include<bits/stdc++.h> using namespace std; double a,b,c,d; double f(double x){ return a*x*x*x+b*x*x+c*x+d; } int main() { cin>>a>>b>>c>>d; for(int x=-100;x<=100;x++){ double x1=x,x2=x+1; if(f(x1)==0) cout<<fixed<<setprecision(2)<<x1<<" "; else if(f(x1)*f(x2)<0){ while(x2-x1>=0.001){ double mid=(x2+x1)/2; if(f(x1)*f(mid)<=0){ x2=mid; }else{ x1=mid; } } cout<<fixed<<setprecision(2)<<x1<<" "; } } return 0; }