ITPEC FE Subject B April 2024 Question 3
ITPEC FE Subject B April 2024 — Question 3 of 20
Identifying even numbers using the modulo operator in pseudocode.
The program loops i from 1 to 100 and should output only even numbers, then print their sum. An even number satisfies the condition i mod 2 = 0 (remainder of division by 2 is zero).
Why not others:
- (a) `i ÷ 2 = 0` — integer division: i ÷ 2 equals 0 only when i is 0 or 1 (since 1 ÷ 2 = 0 in integer arithmetic). Does not test for evenness.
- (b) `i ÷ 2 ≠ 0` — true for almost all values of i (all except 0 and 1), so it would output nearly every number, not just evens.
- (d) `i mod 2 ≠ 0` — selects odd numbers (remainder is 1), the opposite of what is needed.
- (e) `i = 2` — only true once, so only the number 2 would be output.
- (f) `i ≠ 2` — true for every number except 2, outputting 1, 3, 4, 5, …, 100.
Key rule: x mod n = 0 checks divisibility — use it to filter multiples (even numbers = multiples of 2).
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.