#include<stdio.h>
#include<math.h>
int main()
{
double a,b,c;
printf("请输入方程的二次项a,一次项b,常数项c:");
scanf("%lf%lf%lf",&a,&b,&c);
printf("\n");
if(a != 0)
{
double delta;
delta = b*b - 4*a*c;
if(delta > 0)
{
double x1,x2;
x1 = (-b+sqrt(delta))/2*a;
x2 = (-b-sqrt(delta))/2*a;
printf("方程有两个不相等的实根,x1=%.3f x2=%.3f",x1,x2);
}
else if(delta == 0)
{
double x1,x2;
x1 = x2 = -b/2*a;
printf("方程有两个相等实根,x1=x2=%.3f",x1);
}
else
{
double x1s,x1x,x2s,x2x;
x1s = x2s = -b/(2*a);
x1x = x2x = (-delta)/(2*a);
printf("方程有两个虚根,x1=%.3f+%.3fi x2=%.3f-%.3fi",x1s,x1x,x2s,x2x);
}
}
if(a == 0)
{
if(b == 0)
{
printf("方程无解!");
}
else if(b != 0)
{
if(c != 0)
{
double x;
x = -c/b;
printf("方程只有一个解,x=%.3f",x);
}
else if(c == 0)
{
double x;
printf("方程只有一个为0的根,x=%.3f",x);
}
}
}
return 0;
}