ITPEC FE Subject B October 2025 Question 4
ITPEC FE Subject B October 2025 — Question 4 of 20
The algorithm extracts digits from right to left using mod 10, then builds the reversed number by shifting the accumulator left (rev × 10) and adding each extracted digit.
- •A: `temp > 0` — the loop must check
temp, notnum, becausetempis the variable being reduced each iteration. Usingnum > 0would create an infinite loop sincenumnever changes. - •B: `rev × 10 + rm` — shifts existing reversed digits left by one decimal place and appends the current digit (
rm). This is the standard "build a number digit by digit" pattern. - •C: `integer part of (temp ÷ 10)` — removes the last digit from
temp(integer division by 10).
Why not others:
- a-d) use num > 0 as the loop condition, but num is never modified → infinite loop
- e) and f) use rm × 10 + rev which reverses the addition order — would produce wrong results (e.g., for 456: first iteration gives 6×10+0=60 instead of 0×10+6=6)
- f) and h) use temp - rm for C, which doesn't properly remove the last digit (456-6=450, not 45)
Key rule: To reverse a number: extract last digit with mod 10, accumulate with rev × 10 + digit, remove last digit with integer part of (n ÷ 10).
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.