ProgrammingModerateLTIMindtree · Cognizant GenC
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer n = 4021, r = 0
while (n > 0)
r = r * 10 + (n mod 10)
n = n / 10
end while
Print r- A. 4021
- B. 1204
- C. 1240
- D. 124
Correct answer: B. 1204
The digits are peeled off from the right: r = 1, 12, 120, 1204.
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? Procedure p(Integer a[], Integer x) a[0] = a[0] + x x = x + 100 a[1] = x return x end…
- What will be the output of the following pseudocode? Integer c = 0 Function inc() c = c + 1 return c end function if (inc() > 0 || inc() >…
- What will be the output of the following pseudocode? Integer i = 5, j j = (i++) + (++i) Print i, j (i++ gives the old value and then adds…
- What will be the output of the following pseudocode? Integer n = 1000, c = 0 while (n != 0) n = n & (n - 1) c = c + 1 end while Print c (&…
- What will be the output of the following pseudocode? Function g(Integer n) if (n == 0) return 0 end if if (n mod 2 == 0) return g(n - 1) +…
- What will be the output of the following pseudocode? Integer a[6] = {1, 2, 3, 4, 5, 6} Procedure rev(Integer l, Integer r) while (l < r)…