ProgrammingVery hardTCS NQT · Infosys · Accenture
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer n = 37
String out = ""
while (n > 0)
out = out + (n mod 2)
n = n / 2
end while
Print out- A. 100101
- B. 010011
- C. 101010
- D. 101001
Correct answer: D. 101001
Remainders arrive from the least significant bit: 1, 0, 1, 0, 0, 1. Since they are appended (not prepended), the string is 101001, the reverse of (37)2 = 100101.
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 c = 0 for (each n from 2 to 29) Boolean prime = true for (each d from 2 while…
- What will be the output of the following pseudocode? Integer A[5] = {5, 1, 4, 2, 8}, t for (each j from 0 to 3) if (A[j] > A[j + 1]) swap…
- What will be the output of the following pseudocode? Integer A[5] = {64, 25, 12, 22, 11} repeat 2 times, with p = 0, then 1 m = index of…
- What will be the output of the following pseudocode? function change(Integer x) x = x + 10 return x 2 end function Integer a = 4, b b =…
- What will be the output of the following pseudocode? function triple(ref Integer x) // pass by reference x = x 3 end function Integer a =…
- What will be the output of the following pseudocode? Integer M[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, s = 0 for (each i from 0 to 2) s…