ITPEC IP April 2019 Question 6

Source exam: ITPEC IP April 2019Topic: Algorithm and Programming

ITPEC IP April 2019 — Question 6 of 100

The final value of x is 5. Initially x = 2 and y = 3. The first loop reduces y to 2 and adds it to x, giving x = 4. Since y is not 1, the loop repeats: y becomes 1 and x becomes 4 + 1 = 5, after which the procedure ends.

Answer (b)

Why not others:
- 4 is the intermediate value after the first iteration

- 7 and 8 would require extra additions after the termination condition is reached

Key rule: Trace assignments in order and test the loop condition only at the stated step using the updated values.

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 IP past-paper collection or Report an issue.