➽ Program:-

#include<stdio.h>

#include<math.h>

int main()

{

    double a, b, c, discriminant, Root1, Root2, realPart, imaginaryPart;

    printf("Enter coefficients(a,b,c): ");

    scanf("%lf %lf %lf", &a, &b, &c);

 

    discriminant = b * b - 4 * a * c;

 

    // For real and different roots

    if (discriminant > 0)

    {

        Root1 = (-b + sqrt(discriminant)) / (2 * a);

        Root2 = (-b - sqrt(discriminant)) / (2 * a);

        printf("Root1 = %.2lf \nRoot2 = %.2lf", Root1, Root2);

    }

 

    // For real and equal roots

    else if (discriminant == 0)

    {

        Root1 = Root2 = -b / (2 * a);

        printf("Root1 = Root2 = %.2lf;", Root1);

    }

 

    // For non real roots

    else

    {

       realPart = -b / (2 * a);

       imaginaryPart = sqrt(-discriminant) / (2 * a);

       printf("Root1 = %.2lf+%.2lfi \nRoot2 = %.2f-%.2fi",  realPart, imaginaryPart,realPart, imaginaryPart);

    }

    return 0;

}

➽ Output:-

Enter coefficients(a,b,c): 7
8.1
10.2
Root1 = -0.58+1.06i
Root2 = -0.58-1.06i