1.代码死循环了
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#define Z 0.0000001
float f(float x);
float p(float x1, float x2);
int main()
{
float x1, x2;
float x0;
float t;
scanf_s("%f,%f", &x1, &x2);
t = p(x1, x2);
printf("x=%6.2f\n", t);
}
float p(float x1, float x2)
{
float x0 = (x1+x2)/2.0;
for (;;)
{
x0 = (x1 + x2) / 2.0;
if ((x0*x0*x0-x0-1) * (x1*x1*x1-x1-1) < Z)
{
x1 = x1;
x2 = x0;
}
else
{
x1 = x0;
x2 = x2;
}
if (fabs(f(0)) < Z)
break;
}
return x0;
}
float f(float x)
{
return x * x * x - x - 1;
}