#include<stdio.h>
#include<math.h>
int main()
{
double a = 0;
double b = 0;
double c = 0;
scanf("%lf %lf %lf",&a,&b,&c);
if(b*b == 4*a*c)
{
printf("x1=x2=%.5lf",(0-b+sqrt(b*b-4*a*c))/(2*a));
}
else if(b*b > 4*a*c)
{
double x1 = (0-b+sqrt(b*b-4*a*c))/(2*a);
double x2 = (0-b-sqrt(b*b-4*a*c))/(2*a);
printf("x1=%.5lf;x2=%.5lf",x1,x2);
}
else if(b*b < 4*a*c)
{
double shi = (0-b) / (2*a);
double xu1 = sqrt(4*a*c-b*b) / (2*a);
printf("x1=%.5lf+%.5lfi;x2=%.5lf-%.5lfi",shi,xu1,shi,xu1);
}
return 0;
}
这个方法有点差,但是好理解
方法很多