Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views1 page

Quadratic Equation Algorithm

Uploaded by

sneha sureddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Quadratic Equation Algorithm

Uploaded by

sneha sureddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

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

You might also like