用弦截法求解一元三次方程的根(利用c语言实现)0
特别v.09.24浏览296次分享举报
#include
#include
float f(x)
{
float a,b,c,d;
float y;
printf("Please input a,b,c,d:\n");
scanf("%f,%f,%f,%f",&d,&d,&d,&d);
y=((a*x+b)*x+c)*x+b;
return (y);
}
float xpoint(x1,x2)
{
float y,x;
y=(x1*f(x2)-x2*f(x1))/(f(x)-f(x1));
return (y);
}
float x1,x2;
{
int i;
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.000001);
rerurn(x);
}
main()
{
float x1,x2,f1,f2,x;
do
{
printf("Please input x1,x2:\n");
scanf("%f,%f",&x1,&x2);
f1=f(x1);
f1=f(x2);
}
while(f(f1*f2)>=0);
x=root(x1,x2);
printf("A root of the eauation is %8.2f",x);
}
错误提示:
--------------------Configuration: 45 - Win32 Debug--------------------
Compiling...
45.C
G:\45.C(15) : error C2065: 'x' : undeclared identifier
G:\45.C(19) : error C2449: found '{' at file scope (missing function header?)
G:\45.C(37) : error C2059: syntax error : '}'
执行 cl.exe 时出错.
45.exe - 1 error(s), 0 warning(s)
请问各位高手,怎么解决?急需