为什么没有结果?
#include <stdio.h>#include <math.h>
float f (float x)
{
float y;
y = x * x * x + 5 * x * x + 16 * x - 80;
return y;
}
float xpoint (float x1, float x2)
{
float x;
x = (x1 * f (x2) - x2 * f (x1)) / (f(x2) - f (x1));
return x;
}
float root (float x1, float x2)
{
float x, y, y1;
y1 = f (x1);
do
{
x = xpoint (x1, x2);
y = f (x);
if (y * y1 > 0)
{
y1 = y;
x1 = x;
}
else
{
x2 = x;
}
}
while (fabs (y) > 0.00001);
return x;
}
void main ()
{
float x, x1, x2, y1, y2;
do
{
printf ("please enter x1 and x2:");
scanf ("%f%f", &x1, &x2);
y1 = f (x1);
y2 = f (x2);
}
while (y1 * y2 > 0);
x = root (x1, x2);
printf ("a root is:%f\n", x);
}