#include<stdio.h>
#include<math.h>
int main()
{
float a3, a2, a1, a0;
scanf_s("%f %f %f %f\n", &a3, &a2, &a1, &a0);
float a, b, mid;
float fmid = 1, fa, fb;
int result = 0;
scanf_s("%f %f\n", &a, &b);
do{
mid = (a + b) / 2;
fmid = a3 * pow(mid, 3) + a2 * pow(mid, 2) + a1 * mid + a0;
fa = a3 * pow(a, 3) + a2 * pow(a, 2) + a1 * a + a0;
fb = a3 * pow(b, 3) + a2 * pow(b, 2) + a1 * b + a0;
if (fmid == 0) {
printf("%.2f\n", mid);
break;
}
else {
if (fmid*fa > 0) {
a = mid;
}
else {
b = mid;
}
}
} while (b - a > 0.01);
if (fmid != 0) {
printf("%.2f\n", (a + b) / 2);
}
}
7-29 二分法求多项式单根
最新推荐文章于 2024-11-08 17:13:17 发布