Quadratic Equation (Roots)
calculate the roots of quadratic equation in easy way in C
#include <stdio.h>
#include <math.h>
int main()
{
float a, b, c, x1, x2, x, d;
printf("Enter the values of a, b, c for the equation ax^2+bx+c=0\n");
scanf("%f%f%f" , &a, &b, &c);
d=b*b-4*a*c; //d=discriminant
if(a==0 && b==0)
{
printf("No Solution\n");
}
else if(a==0)
{
x=(-c)/b;
printf("%f\n" , x);
}
else if(d<0)
{
printf("The Roosts are imaginary\n");
}
else
{
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
printf("The roots are %f & %f\n" , x1, x2);
}
return 0;