Algorithm: Roots of Quadratic Equation
1. Start
2. Input coefficients:
- Read three floating-point numbers a, b, and c from the user.
- Ensure that a ≠ 0.
3. Calculate the discriminant:
D = b^2 - 4ac
4. Check the nature of the roots based on D:
Case 1: D > 0
- Roots are real and distinct.
- root1 = (-b + sqrt(D)) / (2a)
- root2 = (-b - sqrt(D)) / (2a)
Case 2: D == 0
- Roots are real and equal.
- root = -b / (2a)
Case 3: D < 0
- Roots are complex and conjugate.
- real = -b / (2a)
- imag = sqrt(-D) / (2a)
- root1 = real + imag i
- root2 = real - imag i
5. Display the results:
- If real and distinct → print 'Roots are real and distinct' and the two roots.
- If real and equal → print 'Roots are real and equal' and the root.
- If complex → print 'Roots are complex' and display both real and imaginary parts.
6. End