Q.Write the pseudocode to print all multiples of 5 between 10 and 25 (including both 10 and 25).
Loop from 10 to 25 and print the multiples of 5 — either step by 5 directly, or test each number with MOD; the output is 10, 15, 20, 25.
The idea (iteration with a condition). Printing a regular sequence is the natural job of a loop. Two equally valid designs: (a) step by 5 starting at a multiple, so every visited number is automatically a multiple; or (b) scan every number from 10 to 25 and use the remainder operator (MOD) to test divisibility. Version (a) is more efficient; version (b) shows the test explicitly.
Pseudocode — version (a), stepping by 5
PRINT_MULTIPLES_OF_5
SET num = 10
WHILE num <= 25
PRINT num
num = num + 5
END WHILE
END
Pseudocode — version (b), testing with MOD
PRINT_MULTIPLES_OF_5
SET num = 10
WHILE num <= 25
IF num MOD 5 == 0 THEN
PRINT num
END IF
num = num + 1
END WHILE
END
Python verification
for num in range(10, 26, 5):
print(num)
Expected output
10
15
20
25
Dry run of version (a)
| Iteration | num at test | num <= 25? | Printed |
|---|---|---|---|
| 1 | 10 | yes | 10 |
| 2 | 15 | yes | 15 |
| 3 | 20 | yes | 20 |
| 4 | 25 | yes | 25 |
| 5 | 30 | no — loop ends | — |
"Including both 10 and 25" means the condition must be num <= 25 (and range(10, 26, 5) in Python — range(10, 25, 5) would wrongly stop at 20).
The loop prints 10, 15, 20, 25 — every multiple of 5 between 10 and 25, both ends included.
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.