Quadratic Equation program in C

In this example you will learn, how you can find the root of a quadratic equation in c.

b2-4ac is known as discriminant of quadratic equation. it tell the nature of root

if b2-4ac>0 roots are real and different

if b2-4ac<0 roots are complex and different

if b2-4ac=0 roots are real and equal

c program to find the roots of a quadratic equation

#include<stdio.h>
#include<math.h>
int main()
{
    float det,a,b,c,root1,root2,real,imag;
    printf("\n enter the value of coefficint a,b and c:");
    scanf("%f %f %f",&a,&b,&c);
    /* fid the discrimant value*/
    det=(b*b)-(4*a*c);
    if(det>0)
    {
       root1=(-b+sqrt(det))/(2*a);
       root2=(-b-sqrt(det))/(2*a);
       printf("\n root are real and different");
       printf("\n root1=%f and root2=%f",root1,root2);

    }
    else if(det==0)
    {
    	root1=root2=-b/(2*a);
    	printf("\n since d==0, root are real and equal");
    	printf("\n root1=root2=%f",root1);
    }
    else
    {
        real=(-b)/(2*a);
    	imag=sqrt(-det)/(2*a);
    	printf("\n determinant value is less than 0, hence root are complex and diffrent");
    	printf("\n root1=%f+%fi and root2=%f-%fi",real,imag,real,imag);
    }
 return 0;
}

output

enter the value of coefficint a,b and c:5 9 2
 root are real and different
 root1=-0.259688 and root2=-1.540312