---
title: "Algorithm and flowchart: quadratic roots"
subject: "Computer Programming"
chapter: 2
key: "semester_1/computer_programming:algo-flowchart-quadratic"
source: https://www.bctengineer.com/q/semester_1/computer_programming/algo-flowchart-quadratic
site: BCT Engineering
---

# Algorithm and flowchart: quadratic roots

Computer Programming · Chapter 2: Problem solving using Computer

- Asked in: 2068 Shrawan, 10 marks
- Video: [Roots of Quadratic Equation  - Algorithm and Flow Chart - C Programming](https://www.youtube.com/watch?v=ff8M-Ex0cuk) — Ekeeda
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/algo-flowchart-quadratic
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-2

## Question

Draw a flowchart and algorithm to find roots of a quadratic equation (ax² + bx + c = 0). Include all three conditions of the determinant.

## 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).

## Answer

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
1. Start
2. Read `a`, `b`, `c`
3. If `a = 0`, print "Not a quadratic equation" and go to step 11
4. Calculate `D = b*b - 4*a*c`
5. If `D > 0`, go to step 6; otherwise go to step 8
6. Calculate `r1 = (-b + sqrt(D)) / (2*a)` and `r2 = (-b - sqrt(D)) / (2*a)`
7. Print "Real and distinct roots", `r1`, `r2`; go to step 11
8. If `D = 0`, calculate `r = -b / (2*a)`, print "Real and equal roots", `r`, `r`; go to step 11
9. Otherwise (`D < 0`) calculate `re = -b / (2*a)` and `im = sqrt(-D) / (2*a)`
10. Print "Complex roots": `re + i im` and `re - i im`
11. Stop

#### Flowchart
```text
         ( 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.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. D = b^2 - 4ac decides
   A. the value of a
   B. the nature of roots
   C. the sign of c
   D. the number of inputs
   Answer: B. D determines root type. (Key point: Discriminant)

2. If D > 0, the roots are
   A. real and equal
   B. complex conjugates
   C. two real and distinct
   D. none
   Answer: C. Two different real roots. (Key point: D > 0)

3. If D = 0, the root is
   A. complex
   B. r = sqrt(D)/2a
   C. undefined
   D. r = -b/(2a), real and equal
   Answer: D. Equal roots. (Key point: D = 0)

4. For D < 0, imaginary part is
   A. sqrt(-D)/(2a)
   B. sqrt(D)/(2a)
   C. -b/(2a)
   D. D/(2a)
   Answer: A. Use -D under the root. (Key point: D < 0)

5. a=1,b=2,c=5 gives roots
   A. 1 + 2i and 1 - 2i
   B. -1 + 2i and -1 - 2i
   C. -1 and -1
   D. -5 and 5
   Answer: B. D = -16, re = -1, im = 2. (Key point: Example)

## Related in Computer Programming

- [Roots of quadratic equation in C](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aquadratic-roots-c) — Computer Programming, chapter 5
- [Quadratic equation roots in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-quadratic-roots) — Computer Programming, chapter 11, asked 2×
- [Algorithm and flowchart for largest](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aalgorithm-flowchart-largest-n) — Computer Programming, chapter 2
- [Algorithm and flowchart: distance between points](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aalgo-flowchart-distance) — Computer Programming, chapter 2
- [Algorithm and flowchart help; Armstrong flowchart](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aalgorithm-flowchart-armstrong) — Computer Programming, chapter 2

## Related in other subjects

- [DUIS: ∫ (e^(−ax) − e^(−bx))/x dx](https://www.bctengineer.com/question.md?key=semester_1%2Fmathematics_i%3Aduis-e-ax-minus-e-bx) — Mathematics I, chapter 2, asked 9×
- [Test cases for a quadratic equation program](https://www.bctengineer.com/question.md?key=semester_5%2Fsoftware_engineering%3Aquadratic-test-cases) — Software Engineering, chapter 8
- [Parallel operation conditions and three lamp method](https://www.bctengineer.com/question.md?key=semester_5%2Felectric_machines_ii%3Aparallel-conditions-three-lamp) — Electric Machines II, chapter 1, asked 3×
