include
using namespace std;
include<string.h>
include<stdio.h>
include
double f(double a, double b, double c, double d,double x) {
return a * x * x * x + b * x * x + c * x + d;
}
double jie(double a, double b, double c, double d, double left, double right) {
const double m = 0.01;
double mid;
while (right - left > m) {
mid = (right + left) / 2;
if (f(a, b, c, d, mid) == 0)
{
return mid;
}
else if (f(a, b, c, d, left) * f(a, b, c, d, mid) < 0) { right = mid; }
else { left = mid; }
}
return (left + right) / 2;
}
int main() {
double a, b, c, d, root[30] = {};
scanf_s("%lf %lf %lf %lf", &a, &b, &c, &d);
int j = 0;
for (int i = -101; i < 100;) {
if (f(a, b, c, d, i) * f(a, b, c, d, i + 2) <= 0) {
root[j] = jie(a, b, c, d, i, i + 2);
j++;
} i+=2;
}
for (int j = 0; j < 3; j++)
printf("%.2f ", root[j]);
return 0;
}
标签:lf,right,int,double,day4,mid,left From: https://www.cnblogs.com/ph-123456/p/18512733