C Program To Find All Roots of A Quadratic Equation Using Switch Case
C Program To Find All Roots of A Quadratic Equation Using Switch Case
#include <stdio.h>
#include <math.h> /* Used for sqrt() */
int main()
{
float a, b, c;
float root1, root2, imaginary;
float discriminant;
/* Calculate discriminant */
discriminant = (b * b) - (4 * a * c);
case 0:
/* If discriminant is not positive */
switch(discriminant < 0)
{
case 1:
/* If discriminant is negative */
root1 = root2 = -b / (2 * a);
imaginary = sqrt(-discriminant) / (2 * a);
case 0:
/* If discriminant is zero */
root1 = root2 = -b / (2 * a);
return 0;
}
Output
Enter values of a, b, c of quadratic equation (aX^2 + bX + c): 4 -2 -10
Two distinct and real roots exists: 1.85 and -1.35