Sample questions
Question 1Easy
What will be printed by the following pseudocode?
Integer a, b
Set a = 10, b = 1
a = a + b
b = b + a
a = a - b
Print a, b
Printed values are separated by spaces.
- -1 11
- -1 13
- 0 12
- -1 12
Answer: D. -1 12
Explanation
Update in order: a = -1, b = 12.
Step-by-step solution
- a = 10 + 1 = 11.
- b = 1 + 11 = 12, using the new value of a.
- a = 11 - 12 = -1. The output is -1 12: option D.
Why the other options are wrong
- A. B is 12, not 11, because b = 1 + 11.
- B. B is 12, not 13, because 1 + 11 is 12.
- C. A is -1, not 0, because 11 - 12 is -1.
Tip: Each assignment uses the values as they are after the line before it.
Question 2Easy
What will be printed by the following pseudocode?
Integer h, m, t
Set h = 9, m = 30
t = (h * 60 + m + 95) mod 1440
Print t / 60, t mod 60
/ denotes integer division (the fractional part is discarded). Printed values are separated by spaces.
- 0 0
- 5 5
- 11 5
- 11 6
Answer: C. 11 5
Explanation
Convert to minutes since midnight, add 95, wrap at 1440, and convert back: 11 5.
Step-by-step solution
- 9 × 60 + 30 = 570 minutes.
- 570 + 95 = 665. That is less than 1440, so there is no wrap.
- 665 ÷ 60 = 11 with 5 minutes left, so the output is 11 5, the correct answer.
Why the other options are wrong
- A. 0 0 is wrong; 665 minutes is 11 hours and 5 minutes.
- B. 5 5 is wrong; 665 ÷ 60 = 11, not 5.
- D. 11 6 is wrong; 665 − 660 = 5 minutes, not 6.
Tip: For clock arithmetic, convert to minutes, add, take the remainder after dividing by 1440, then convert back to hours and minutes.
Question 3Easy
What will be the output of the following pseudocode?
Integer a, b
Set a = 3, b = 4
a = a + b
b = b + a
a = a - b
Print a, b
Printed values are separated by spaces.
- -3 11
- -4 11
- -4 10
- -4 12
Answer: B. -4 11
Explanation
Update in order: a = -4, b = 11.
Step-by-step solution
- a = 3 + 4 = 7.
- b = 4 + 7 = 11, using the new value of a.
- a = 7 - 11 = -4. The output is -4 11: option B.
Why the other options are wrong
- A. A is -4, not -3, because 7 - 11 is -4.
- C. B is 11, not 10, because b = 4 + 7.
- D. B is 11, not 12, because 4 + 7 is 11.
Tip: Each assignment uses the values as they are after the line before it.
Question 4Easy
What will be printed by the following pseudocode?
Integer a, b, c
Set a = 50, b = 8
c = a mod b * 2 + a / b
Print c
/ denotes integer division (the fractional part is discarded).
- 11
- 18
- 6
- 10
Answer: D. 10
Explanation
mod, * and / share one precedence level and group left to right: (50 mod 8) * 2 + (50 / 8) = 10.
Step-by-step solution
- 50 mod 8 is 2, because 8 × 6 = 48 and 50 - 48 = 2.
- 2 × 2 = 4, and 50 / 8 is 6 with integer division.
- 4 + 6 = 10. The output is 10: option D.
Why the other options are wrong
- A. 11 would need 50 / 8 to be 7; integer division gives 6.
- B. 18 would need the remainder to be 6; 50 mod 8 is 2.
- C. 6 is only the quotient; the remainder term adds 4.
Tip: Mod, * and / share one precedence and go left to right, while + and - come after them.
Question 5Medium
What will be the output of the following pseudocode?
Integer d, n, v
Set n = 1101, v = 0
while (n > 0)
d = n mod 10
v = v * 2 + d
n = n / 10
End while
Print v
/ denotes integer division (the fractional part is discarded).
- 10
- 12
- 11
- 926
Answer: C. 11
Explanation
Digits are read from the right, so this builds the binary value of the REVERSED digit string: 11.
Step-by-step solution
- n = 1101, v = 0.
- First loop: d = 1, v = 0 * 2 + 1 = 1, n = 110.
- Second loop: d = 0, v = 1 * 2 + 0 = 2, n = 11.
- Third loop: d = 1, v = 2 * 2 + 1 = 5, n = 1.
- Fourth loop: d = 1, v = 5 * 2 + 1 = 11, n = 0.
Why the other options are wrong
- A. 10 is one less; v gets 1, 2, 5 and 11 in turn, so the final v is 11.
- B. 12 is one more than the final v, which is 11.
- D. 926 is not produced; the loop reads the digits 1, 0, 1, 1 in base 2, giving 11.
Question 6Medium
Predict the output of the following pseudocode.
Integer n, s
Set n = 20
s = n * (n + 1) / 2 - (n / 3) * 3 * ((n / 3) + 1) / 2
Print s
/ denotes integer division (the fractional part is discarded).
- 147
- -63
- 146
- 148
Answer: A. 147
Explanation
The sum 1..20 minus the multiples of 3 (3 + 6 + ...): 147.
Step-by-step solution
- 20 × 21 ÷ 2 = 210.
- 20 ÷ 3 = 6 with integer division. Then 6 × 3 × 7 ÷ 2 = 126 ÷ 2 = 63.
- 210 − 63 = 147, the correct answer.
Why the other options are wrong
- B. -63 is wrong; 210 is the first part, and the answer is 210 − 63.
- C. 146 is wrong; 210 − 63 = 147.
- D. 148 is wrong; the answer is 147.
Tip: Multiplications and divisions run left to right, so the sum of multiples of 3 is 6 × 3 × 7 ÷ 2 here.
Question 7Medium
What will be the output of the following pseudocode?
Integer a, b, c
Set a = 29, b = 4
c = a / b * b
Print c, a - c
/ denotes integer division (the fractional part is discarded). Printed values are separated by spaces.
- 28 1
- 28 2
- 4 25
- 29 1
Answer: A. 28 1
Explanation
a / b * b rounds 29 down to a multiple of 4, so c = 28, and a - c is the remainder; the output is 28 1.
Step-by-step solution
- a / b = 7 (integer division)
- 7 * b = 28.
- a - c = 29 - 28 = 1.
Why the other options are wrong
- B. 28 2 is wrong; a minus c is 29 minus 28, which is 1.
- C. 4 25 is wrong; c is 28, not 4, because c equals 7 times 4.
- D. 29 1 is wrong; c is 28, not 29, because integer division drops the remainder.
Tip: Remember integer division truncates towards zero.
Question 8Medium
What will be the output of the following pseudocode?
Integer n, r
Set n = 4729
r = (n mod 1000) / 100 * 100 + n / 1000 + n mod 100
Print r
/ denotes integer division (the fractional part is discarded).
- 33
- 2933
- 734
- 733
Answer: D. 733
Explanation
Evaluate each part with integer arithmetic: the hundreds digit times 100, plus the thousands digit, plus the last two digits, giving 733.
Step-by-step solution
- N mod 1000 = 729, and 729 / 100 = 7 (integer), so the first term is 7 x 100 = 700.
- n / 1000 = 4, the second term.
- N mod 100 = 29, the third term.
- r = 700 + 4 + 29 = 733, which is option D.
Why the other options are wrong
- A. 33 leaves out the 700 from the hundreds digit, so it is not the sum of the three terms.
- B. 2933 joins digits together instead of adding the terms.
- C. The last two digits give 29, not 30, so the sum is 733, not 734.
Tip: Split a 4-digit number into thousands, hundreds and last two digits, then add the three parts.
Question 9Hard
What is the output of the following pseudocode?
Integer y, c, a, b, d, e
Set y = 2024
a = y mod 19
b = y / 100
c = y mod 100
d = (19 * a + b - b / 4 + 15) mod 30
Print a, d
/ denotes integer division (the fractional part is discarded). Printed values are separated by spaces.
- 10 11
- 106 4
- 10 10
- 10 13
Answer: C. 10 10
Explanation
Evaluate each line with integer division and mod:
a = 10, b = 20, c = 24, d = 10.
Step-by-step solution
- a = 2024 mod 19 = 10, since 19 × 106 = 2014 and 2024 - 2014 = 10.
- b = 2024 / 100 = 20 with integer division.
- d = (19 × 10 + 20 - 20 / 4 + 15) mod 30 = (190 + 20 - 5 + 15) mod 30 = 220 mod 30 = 10. The output is 10 10: option C.
Why the other options are wrong
- A. 11 is not d; (190 + 20 - 5 + 15) mod 30 is 10.
- B. 106 is the quotient 2024 / 19, not a remainder; a is 10.
- D. 13 is not d; the value of d is 10.
Tip: Work each line in order with integer division and mod, and keep the running values written down.
Question 10Hard
Predict the output of the following pseudocode.
Integer a, b, c
Set a = 17, b = 40, c = 0
while (b > 0)
if (b mod 2 == 1)
c = c + a
End if
a = a * 2
b = b / 2
End while
Print c
/ denotes integer division (the fractional part is discarded).
- 681
- 680
- 272
- 0
Answer: B. 680
Explanation
This is Russian peasant multiplication: adding a whenever b is odd while doubling a and halving b computes 17 * 40 = 680.
Step-by-step solution
- b = 40 is even, so c stays 0 and a doubles to 34; then b = 20, a = 68, b = 10, a = 136, b = 5.
- b = 5 is odd, so c = 0 + 136 = 136; then a = 272 and b = 2.
- b = 2 is even, so a = 544 and b = 1.
- b = 1 is odd, so c = 136 + 544 = 680, which is option B.
Why the other options are wrong
- A. 681 is not reachable; the added values are 136 and 544, which sum to 680.
- C. 272 is only one doubled value of a; c adds 136 and 544, not 272.
- D. C does get added to, because 40 has 1-bits in binary (101000), so c is not 0.
Tip: This is shift-and-add multiplication: 17 x 40 is built from the 1-bits of 40, doubling a at each bit.
Practise all 52 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →