ITPEC FE Subject B October 2024 Question 6
From the answer group below, select the correct combination of answers to be inserted into A through C in the program.
The standard form of a quadratic equation is as follows:
ax2 + bx + c = 0, where a, b and c are real numbers and a ≠ 0.
Here, the term b2 - 4ac is known as the discriminant of a quadratic equation. It indicates the nature of the roots. The formula for solving a quadratic equation is shown in the figure. If the discriminant value is positive, there are two solutions; if it is zero, there is one solution. Here, we assume that the discriminant value is non-negative.
Figure The formula for solving a quadratic equation
The procedure findRoots receives three real number arguments a, b, and c as coefficients and outputs the value of the root(s) of the quadratic equation. Function sqrt( returns the principal square root value of the parameter discriminant.
Answer group
Explanation
A: b × b - 4 × a × c, B: discriminant > 0, C: discriminant = 0 — compute b2 - 4ac, then take the two-root branch when it is positive and the one-root branch when it is zero.
b2 is b multiplied by itself, so blank A is b × b - 4 × a × c. The if branch outputs two different roots using sqrt(, which matches the figure's "discriminant > 0" row. The elseif branch outputs the single root -b ÷ 2a, the "discriminant = 0" row. The question excludes negative values, so no third branch is needed.
Check with x2 - 3x + 2 = 0 (a = 1, b = -3, c = 2): the discriminant is 9 - 8 = 1 > 0, so the program outputs root1 = 2 and root2 = 1.
Answer (h)
Why not others:
- •(a), (b), (c) and (d) — A as
b × 2 - 4 × a × ccomputes 2b - 4ac rather than squaring b; in the example it gives -6 - 8 = -14 instead of 1. In (d) this is the only wrong blank - •(a) and (e) — B
discriminant < 0sends only negative values to the two-root branch, wheresqrthas no real result, and a positive discriminant reaches no branch at all - •(b) and (f) — B
discriminant = 0computes the repeated root through the two-root formula, and Cdiscriminant < 0never holds, so a positive discriminant outputs nothing - •(c) and (g) — B and C are swapped: a positive discriminant goes to the single-root branch and outputs only -b ÷ 2a, dropping the square-root term
Key rule: Pseudocode has no superscript: a square is written x × x (or with pow), never x × 2; and match each branch to the case whose formula it uses.
Math & Numbers · AI-written, may contain errors
This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.