ProgrammingModerateTCS NQT · Accenture pattern
What will be the output of the following pseudocode? (All variables are integers, so / is integer division.)
What will be the output of the following pseudocode? (All variables are integers, so / is integer division.)
Integer n = 2048, c = 0, d
while (n > 0)
d = n mod 10
if (d != 0 && 2048 mod d == 0)
c = c + 1
end if
n = n / 10
end while
Print c- A. 3
- B. 2
- C. Error: division by zero
- D. 4
Correct answer: A. 3
The digits are 8, 4, 0, 2. 2048 is divisible by 8, 4 and 2. For the digit 0, the d != 0 check is false and && short-circuits, so 2048 mod 0 is never worked out. Count = 3.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division.) Function f(Integer n) if (n…
- What will be the output of the following pseudocode? Integer s = 0 for (each i from 1 to 3) for (each j from 1 to 3) if (i == j) continue…
- What will be the output of the following pseudocode? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right…
- What will be the output of the following pseudocode? (Arrays are indexed from 0.) Integer arr[5] = {1, 2, 3, 4, 5} Integer t for (each k…
- What will be the output of the following pseudocode? Integer s = 0, i = 1 while (i <= 20) s = s + i i = i 2 + 1 end while Print s
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division.) Function g(Integer n) if (n…