ITPEC FE Subject B October 2025 Question 14

Source exam: ITPEC FE Subject B October 2025Topic: Array Manipulation

ITPEC FE Subject B October 2025 — Question 14 of 20

Filling in the condition to validate a 3×3 normal magic square

The program computes rowSum[k], colSum[k], dia1Sum, and dia2Sum in the first loop, then checks dia1Sum ≠ dia2Sum to reject early. The blank is the guard inside the final for k loop that must reject the matrix if any row or column sum deviates.

  • The if triggers return false, so it must catch invalid cases
  • A magic square requires rowSum[k] = colSum[k] = dia1Sum for every k
  • Invalidity means at least one equality fails → use or (disjunction)
OptionConditionVerdict
a) = and =Checks both match → would reject valid squaresWrong
b) = or =Checks at least one matches → rejects almost everythingWrong
c) ≠ and ≠Both must fail simultaneously → misses cases where only one failsWrong
d) ≠ or ≠At least one fails → correctly catches any deviationCorrect

Why not others:
- a) and b) use equality checks (=), meaning the if fires when sums are equal — the opposite of what we want

- c) uses and with inequality, so it only catches the case where both row≠col and row≠diagonal simultaneously; a row matching the column but not the diagonal would slip through

Key rule: When guarding against invalidity, use ≠ ... or ≠ ... (reject if any condition fails). Use ≠ ... and ≠ ... only when you need all conditions to fail simultaneously.

AI-generated — may contain errors

The original exam layout is preserved in the image so diagrams, formulas, tables, and code remain accurate.

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.