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.

If the discriminant > 0root1 = −b + √b2 − 4ac2aroot2 = −b − √b2 − 4ac2a
If the discriminant = 0root1 = root2 = −b2a

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(discriminant) returns the principal square root value of the parameter discriminant.

[Program]
○ findRoots(real: a, real: b, real: c)
real: discriminant, root1, root2
discriminant ← A
if (B)
root1 ← (-b + sqrt(discriminant)) ÷ (2 × a)
root2 ← (-b - sqrt(discriminant)) ÷ (2 × a)
output "root1 = ", root1, " and root2 = ", root2
elseif (C)
root1 ← -b ÷ (2 × a)
output "root1 = root2 = ", root1
endif

Answer group

OptionABC

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(discriminant), 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 × c computes 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 < 0 sends only negative values to the two-root branch, where sqrt has no real result, and a positive discriminant reaches no branch at all
  • •(b) and (f) — B discriminant = 0 computes the repeated root through the two-root formula, and C discriminant < 0 never 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.