ITPEC FE Subject B April 2025 Question 1
ITPEC FE Subject B April 2025 — Question 1 of 20
Leap Year Algorithm — fill in conditions for a leap year checker using modular arithmetic.
The leap year rule has three tiers, checked from most specific to least:
- Divisible by 400 → leap year (
year mod 400 = 0→return true) - Divisible by 100 → NOT a leap year (
year mod 100 = 0→return false) - Divisible by 4 → leap year (
year mod 4 = 0→return true) - Otherwise → NOT a leap year (
return false)
The program checks the 400 case first (slot A = year mod 400 = 0), returns true (slot B), then checks the 100 case (slot C = year mod 100 = 0) and returns false. The remaining mod 4 branch is already provided.
Verification with known years:
- 2000: 2000 mod 400 = 0 → true ✓ (leap)
- 1900: mod 400 ≠ 0, mod 100 = 0 → false ✓ (not leap)
- 2024: mod 400 ≠ 0, mod 100 ≠ 0, mod 4 = 0 → true ✓ (leap)
Why not others:
- (a) A = mod 100, B = false — would return false for year 1900 (correct) but also false for year 2000 (wrong, 2000 is a leap year)
- (b) A = mod 100, B = true — returns true for all centurial years, making the mod 400 check in C useless
- (c) Same as (a) but with ≠ in C, breaks the 400-year exception logic
- (d) A = mod 100 ≠ 0, B = true — would return true for non-centurial years without checking mod 4
- (e) A = mod 400, B = false — returns false for years divisible by 400 (wrong, they are leap years)
- (g) A = mod 400 ≠ 0 — the first check catches all years NOT divisible by 400, which is almost every year
- (h) A = mod 400 ≠ 0, B = true — returns true for nearly all years
Key rule: When implementing leap year logic, always check divisibility by 400 first, then 100, then 4 — from most specific to least specific.
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.