[求助]弦切法求函数根(函数调用),这个程序结果为什么错误?
可以通过编译,我检查了很多遍,输出结果就是不对。很苦恼,请帮忙看一下哪里错了?#include<stdio.h>
#include<math.h>
float f(float x)
{return ((x-5)*x+16)*x-80;
}
float xpoint(float x1,float x2)
{return (x1*f(x2)-x2*f(x1))/(f(x2)-f(x1)) ;
}
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)
{x1=x;y1=y;
}
else
{x2=x;
}
}while(fabs(y)>0.00001);
return x;
}
void main()
{ float x,x1,x2,y1,y2;
do
{ printf("Input x1,x2:");
scanf("%f,%f",&x1,&x2);
y1=f(x1);y2=f(x2);
}while(y1*y2>0);
x=root(x1,x2);
printf("The root is:%f\n",x);
getch();
return(0);
}