帮帮忙,看看我哪错了要求用优选发求根,函数自选
#include<math.h>
#define E 0.01
float d;
int a,b,c;
main()
{
float s;
void funChose(float x1[],float x2[]);
int Judge();
float fn(float x);
float x1[2]={0,0},x2[2]={0,0};
step:printf("input a,b,c\n");
scanf("%a,%b,%c",&a,&b,&c);
if(Judge(a,b,c))
goto step;
s=fn(x1[0])*fn(x2[0]);
while(s>=0)
{
printf("Input x1,x2,and there must be only one value between x1 and x2\n");
scanf("%f,%f",&x1[0],&x2[0]);
}
while(abs(fn(d)>E)
funChose(x1,x2);
printf("The value is %d",fn(d));
}
int Judge()
{
return b*b-4*a*c<=0;
}
float fn(float x)
{
return a*x*x+b*x+c;
}
void funChose(float x1[],float x2[])
{
d=x1[0]+0.618*(x2[0]-x1[0]);
x1[1]=(fn(x1[0])*fn(d)>0)?d:x1[0];
x2[1]=(fn(x2[0])*fn(d)>0)?d:x2[0];
x1[0]=x1[1];
x2[0]=x2[1];
}
#include<math.h>
#define E 0.01
float d;
int a,b,c;
main()
{
float s;
void funChose(float x1[],float x2[]);
int Judge();
float fn(float x);
float x1[2]={0,0},x2[2]={0,0};
step:printf("input a,b,c\n");
scanf("%a,%b,%c",&a,&b,&c);
if(Judge(a,b,c))
goto step;
s=fn(x1[0])*fn(x2[0]);
while(s>=0)
{
printf("Input x1,x2,and there must be only one value between x1 and x2\n");
scanf("%f,%f",&x1[0],&x2[0]);
}
while(abs(fn(d)>E)
funChose(x1,x2);
printf("The value is %d",fn(d));
}
int Judge()
{
return b*b-4*a*c<=0;
}
float fn(float x)
{
return a*x*x+b*x+c;
}
void funChose(float x1[],float x2[])
{
d=x1[0]+0.618*(x2[0]-x1[0]);
x1[1]=(fn(x1[0])*fn(d)>0)?d:x1[0];
x2[1]=(fn(x2[0])*fn(d)>0)?d:x2[0];
x1[0]=x1[1];
x2[0]=x2[1];
}
while(abs(fn(d)>E)
后面少了括号 while(abs(fn(d)>E))
scanf("%a,%b,%c",&a,&b,&c);
if(Judge(a,b,c))
goto step;
就是段代码