ProgrammingModerateWipro · Accenture pattern
What will be the output of the following pseudocode? (/ is integer division.)
What will be the output of the following pseudocode? (/ is integer division.)
Integer n = 25, z = 0
while (n > 0)
n = n / 5
z = z + n
end while
Print z- A. 5
- B. 7
- C. 25
- D. 6
Correct answer: D. 6
This counts the trailing zeros of 25!: 25/5 = 5 multiples of 5, then 5/5 = 1 multiple of 25 (contributing an extra 5), then 0. 5 + 1 = 6. Counting only the multiples of 5 gives 5.
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? Integer s = 0 for (i = 1 to 30) if (i mod 4 == 0) continue end if if (i mod 7 == 0)…
- What will be the output of the following pseudocode? (Byte variables are 8-bit unsigned: they hold 0–255 and arithmetic wraps modulo 256.)…
- What will be the output of the following pseudocode? (Strings are indexed from 0; swap exchanges two characters.) String s = "ABCDEF"…
- What will be the output of the following pseudocode? Integer c = 0 for (i = 1 to 5) for (j = i to 5) if ((i + j) mod 3 == 0) c = c + 1 end…
- What will be the output of the following pseudocode? (/ is integer division; calls counts every call of f.) Integer calls = 0 Function…
- What will be the output of the following pseudocode? (Arrays are indexed from 0.) Integer a[5] = {1, 2, 3, 4, 5}, t for (i = 0 to 4) t =…