Printf("Enter values of a, b, c of quadratic equation (aX^2 + bX + c): ") * C program to find all roots of a quadratic equation using switch case Program to find roots of quadratic equation using switch.case Whereas case 0 means discriminant is zero.ĩ.Apply the formula to compute roots for both the inner cases. switch(discriminant < 0).ħ.Inside case 0 switch the expression switch(discriminant < 0).Ĩ.For the above nested switch there are two possible cases. There exist one more condition to check i.e. Apply formula root1 = (-b + sqrt(discriminant)) / (2*a) to compute root1 and root2 = (-b - sqrt(discriminant)) / (2*a) to compute root2.Ħ.For case 0 means discriminant is either negative or zero. ![]() case 0 and case 1.ĥ.For case 1 means discriminant is positive. Switch the value of switch(discriminant > 0).Ĥ.The expression (discriminant > 0) can have two possible cases i.e. ![]() You can also use pow() function to find square of b.ģ.Compute the roots based on the nature of discriminant. Store it in some variable say a, b and c.Ģ.Find discriminant of given equation using formula i.e. Step by step descriptive logic to find roots of quadratic equation using switch case.ġ.Input coefficients of quadratic equation. ![]() ![]() Logic to find roots of quadratic equation using switch.case
0 Comments
Leave a Reply. |