解一元二次方程(三个错误,但不知道错哪里了)
#include
#include
int main()
{
float a, b, c, x1, x2, t;
scanf("%f %f %f", &a, &b, &c);
double d = b*b - 4.0 * a*c;
t=sqrt(d);
if (a != 0)
{
if(t>0)
{
x1=(-b-sqrt(d))/(2*a);
x2=(-b+sqrt(d))/(2*a);
printf("%.4f %.4f\n",x1,x2);
}
else if(t=0)
{
x1=-b/(2*a);
x2=x1;
printf("%.4f\n",x1);
}
else if(t<0)
{
printf("no answer\n");
}
}
return 0;
}
double d = bb - 4.0 * ac;
t=sqrt(d);
如果d小于0,是不能开根号的,这时候才是输出No answer的时候
=============
else if(t=0)
应该是
else if(t==0)
=============
另外,当a=0时,也是有解的,没处理