不会二分就暴力计算
提示:记方程f(x)=0f(x)=0,若存在22个数x_1x1?和x_2x2?,且x_1<x_2x1?<x2?,f(x_1) \times f(x_2)<0f(x1?)×f(x2?)<0,则在(x_1,x_2)(x1?,x2?)之间一定有一个根。
#include<iostream>
#include<cstdio>
#include<cmath>
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()
{
scanf("%lf %lf %lf %lf",&a,&b,&c,&d);
for(double i=-100;abs(i)<=100;i=i+0.00001)
{
double j=i+0.00001;
if(f(i)*f(j)<=0)
{
i=(i+j)/2.00;
printf("%.2lf ",i);
}
}
}
原文:https://www.cnblogs.com/xiaoyezi-wink/p/10404032.html