上回我发的有点小错误,现在予以纠正(经过wintc验证):
#include "stdio.h"
#include "math.h"
float f(float x)
{
float y;y=x*x*x+x-1;return y;
}
float f1(float x)
{
float y;y=3*x*x+1;return y;
}
main()
{
float k,x=0;
do
{
k=x;x=k-f(k)/f1(k);
}
while (fabs(x-k)>1.0/1000000);
printf("the number is %f\n",x);getch();
}