ITPEC FE Subject A October 2024 Question 6
ITPEC FE Subject A October 2024 — Question 6 of 60
Recursive sum f(n) — compute f(5) for a recursive function.
f(n): if n ≤ 1 return 1, else return n + f(n−1)
- •f(5) = 5 + f(4) = 5 + 4 + f(3) = … =
5 + 4 + 3 + 2 + 1= 15
This is the classic sum formula: n × (n + 1) / 2 = 5 × 6 / 2 = 15
Why not others:
- (a) 6 — this is f(3) = 3 + 2 + 1
- (b) 9 — this is f(3) + f(2) or a miscalculation
- (d) 25 — confuses with n², i.e. 5 × 5
Key rule: When a recursive function adds n + f(n−1) with base case f(1) = 1, it computes the sum 1 + 2 + … + n.
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.