/*
Author : Ashish Yadav
Title : Roots of a Quadratic equation
Compiler : GNU-GCC Compiler (Code::Blocks v16.01)
Os : Windows 10 Pro
*/
#include <stdio.h>
#include <math.h>
int main()
{
double a,b,c,d,e,f,root1,root2,i;
printf("\n----------Roots of A quadratic Equation-------------\n");
printf(" Please enter value of (except 0) a \n");
scanf("%lf",&a);
if (a==0)
{
printf("\n value of a cannot be 0");
} else
{
printf(" Please enter value of b \n");
scanf("%lf",&b);
printf(" Please enter value of c \n");
scanf("%lf",&c);
d = b*b-4*a*c;
e = -b/(2*a);
i = sqrt(-d)/(2*a);
if (d>0)
{
f = sqrt(d)/(2*a);
root1 = e+f;
root2 = e-f;
printf("\n--------------------------------------------------\n");
printf("\n Real roots are :%lf,%lf",root1,root2);
}
else
if (d==0)
{
printf ("Root is:%lf",e);
} else
{
printf("\n----------------------------------------------------\n");
printf("\n imaginary roots are:%lf+%lfi,%lf-%lfi",e,i,e,i);
}
}
getch();
return 0;
}