一元2次方程 c language

来源:百度知道 编辑:UC知道 时间:2024/07/17 00:01:37

#include <stdio.h>
#include <math.h>

int main()
{
double a,b,c;

printf("Input coefficients for ax^2+bx+c=0\n");
scanf("%lf %lf %lf",&a,&b,&c);
if(a==0)
{
//this equation is LINEAR
if(b==0)
{
//c=0
if(c==0)
printf("Any real number X");
else
printf("No solution.");

}
else
{
printf("X1 = %lf", -c/b);
}
}
else
{
if(b*b-4*a*c<0)
{
printf("No solution.");
}
else if(b*b-4*a*c==0)
{
printf("X1 = %lf", -b/2/a);
}
else
{
printf("X1 = %d, X2 = %d", (-b+sqrt(b*b-4*a*c))/(2*a),(-b-sqrt(b*b-4*a*c))/(2*a));
}
}

}

什么意思