ITPEC FE Subject A October 2025 Question 6
The flowchart shown below expresses an algorithm that determines the greatest common divisor between two integers a and b. How many times is A passed?
Explanation
2 — the official key counts the two passes through the loop that computes the remainder.
Trace Euclid's algorithm with a = 56, b = 48:
- •Pass 1: r = 56 mod 48 = 8, then a = 48, b = 8; r ≠ 0, so control takes the No branch back to the top
- •Pass 2: r = 48 mod 8 = 0, then a = 8, b = 0; r = 0, so control takes the Yes branch and prints 8
Note on the key: ITPEC's official answer is (b) 2, and that is what the exam scores. Read strictly, circle A sits on the No branch, which is taken only once, so the drawing supports 1. The key treats A as marking the loop itself, which runs twice. Choose (b) on the exam.
Answer (b)
Why not others:
- •(a) 1 — the number of times the No branch is taken as drawn; defensible, but not the official answer
- •(c) 4 — would need four remainders before one reaches 0, but 48 mod 8 is already 0 on the second pass
- •(d) 8 — the greatest common divisor the flowchart prints, not a count of passes
Key rule: Euclid's algorithm repeats "remainder, then shift b into a and r into b" until the remainder is 0; count the loop passes by tracing the remainders, and keep the pass count apart from the GCD it prints.
Algorithm and Programming · 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.