牛顿迭代法求方程根
#include <stdio.h>
#include<math.h>
int main()
{
float a, b, c, d;
float f, F;
float x = 1.5, x0;
printf("输入方程系数:");
scanf_s("%f %f %f %f", &a, &b, &c, &d);
do{
x0 = x;
f = a * pow(x0, 3) + b * pow(x0, 2) + c * x0 + d;
F = 3 * a * x0 * x0 + 2 * b * x0 + c;
x = x0 - f / F;
} while (fabs(x - x0) >= 1e-5);
printf("x = %f", x);
}