有无朋友来讲解一下这个解方程怎么实现?

img

#include <stdio.h>
#include <math.h>
int main()
{
    int a,b,c,d;
    double x1,x2;
    scanf("%d,%d,%d",&a,&b,&c);
    if(a != 0)
    {
        d = b*b - 4*a*c;
        if(d < 0)
        {
            x1 = -b/(2.0*a);
            x2 = sqrt(4.0*a*c-b*b);
            printf("The equation has complex roots:\n");
            printf("%.4lf+%.4lfi\n",x1,x2);
            printf("%.4lf-%.4lfi\n",x1,x2);
        }else
        {
            x1 = (-b + sqrt((double)b*b-4*a*c))/(2*a);
            x2 = (-b - sqrt((double)b*b-4*a*c))/(2*a);
            if(x1 == x2)
                printf("The equation has two equal roots:%.4lf",x1);
            else
                printf("The equation has distinct real roots:%.4lf and %.4lf",x1,x2);
        }
        
    }else
        printf("The equation is not a quadratic");
    
    return 0;
}