ProgrammingHardTCS Digital · Infosys pattern
What will be the output of the following pseudocode? (reverse(x) returns x with its decimal digits reversed.)
What will be the output of the following pseudocode? (reverse(x) returns x with its decimal digits reversed.)
Integer n = 87, k = 0
while (n != reverse(n))
n = n + reverse(n)
k = k + 1
end while
Print k, n- A. 3 1353
- B. 4 1353
- C. 4 4884
- D. 5 4884
Correct answer: C. 4 4884
87 + 78 = 165; 165 + 561 = 726; 726 + 627 = 1353; 1353 + 3531 = 4884, which is a palindrome. Four additions. Stopping at 1353 assumes it is a palindrome (it is not: reversed it is 3531).
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 fun(Integer n) if (n <= 0) return end if fun(n - 2) Print n fun(n - 1) End…
- What will be the output of the following pseudocode? (/ is integer division.) Integer a = 1, b = 100, steps = 0 while (a < b) a = a 2 b =…
- What will be the output of the following pseudocode? (calls counts every call, including the first; memo starts with every entry equal to…
- What will be the output of the following pseudocode? (/ is integer division.) Integer c = 0 for (n = 1 to 50) Integer d = 0 for (k = 1 to…
- What will be the output of the following pseudocode? (&, |, ^ are bitwise AND, OR, XOR; << is a left shift.) Integer x = 0 for (i = 0 to…
- What will be the output of the following pseudocode? ('ref' parameters are passed by reference; others by value.) Procedure p(ref Integer…