方程求解~
# include<stdio.h>
# include<math.h>
main()
{ float a,b,c,y,x1,x2;
scanf("%f%f%f",&a,&b,&c);
if(fabs(a)<1e-6)
printf("the equation is not a quadratic");
else
{ y=b*b-4*a*c;
if(fabs(y)<1e-6)
x1=-b/(2*a);x2=-b/(2*a);
else
if(y<0)
printf("the eqnation has not real root");
else
{ x1=(-b+sqrt(y))/(2*a);
x2=(-b-sqrt(y))/(2*a);
}
}
printf("x1=%.2f,x2=%.2f",x1,x2);
}
----------------解决方案--------------------------------------------------------