- 2068 Shrawan · 10 marks
Algorithm and flowchart: quadratic roots
Short answer
Compute discriminant D = b² - 4ac. If D > 0, real distinct roots: (-b ± √D) / (2a); if D = 0, repeated real root: -b / (2a); if D < 0, complex conjugates: real part -b/(2a), imag part ±√(-D)/(2a).
Draw a flowchart and algorithm to find roots of a quadratic equation (ax² + bx + c = 0). Include all three conditions of the determinant.
For ax² + bx + c = 0, the discriminant D = b² - 4ac decides the nature of the roots: D > 0 gives two real and distinct roots, D = 0 gives two real and equal roots, D < 0 gives two complex conjugate roots.
Algorithm
- Start
- Read
a,b,c - If
a = 0, print "Not a quadratic equation" and go to step 11 - Calculate
D = b*b - 4*a*c - If
D > 0, go to step 6; otherwise go to step 8 - Calculate
r1 = (-b + sqrt(D)) / (2*a)andr2 = (-b - sqrt(D)) / (2*a) - Print "Real and distinct roots",
r1,r2; go to step 11 - If
D = 0, calculater = -b / (2*a), print "Real and equal roots",r,r; go to step 11 - Otherwise (
D < 0) calculatere = -b / (2*a)andim = sqrt(-D) / (2*a) - Print "Complex roots":
re + i imandre - i im - Stop
Flowchart
( Start )
|
/ Read a, b, c /
|
< a = 0 ? >--Yes--> / Print "Not quadratic" / --+
| No |
[ D = b*b - 4*a*c ] |
| |
< D > 0 ? >--Yes--> [ r1=(-b+sqrt(D))/(2a) ] |
| No [ r2=(-b-sqrt(D))/(2a) ] |
| / Print r1, r2 / ----------+
< D = 0 ? >--Yes--> [ r = -b/(2a) ] |
| No / Print r, r / ------------+
[ re = -b/(2a) ] |
[ im = sqrt(-D)/(2a) ] |
/ Print re + i im, re - i im / |
| |
+<-----------------------------------------+
|
( Stop )
Example: a = 1, b = 2, c = 5 gives D = 4 - 20 = -16 < 0, so roots are -1 + 2i and -1 - 2i.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Roots of quadratic equation in C · Computer Programming, chapter 5
- Quadratic equation roots in FORTRAN · Computer Programming, chapter 11 · asked 2×
- Algorithm and flowchart for largest · Computer Programming, chapter 2
- Algorithm and flowchart: distance between points · Computer Programming, chapter 2
- Algorithm and flowchart help; Armstrong flowchart · Computer Programming, chapter 2
- DUIS: ∫ (e^(−ax) − e^(−bx))/x dx · Mathematics I, chapter 2 · asked 9×
- Test cases for a quadratic equation program · Software Engineering, chapter 8
- Parallel operation conditions and three lamp method · Electric Machines II, chapter 1 · asked 3×