ProgrammingHardAmazon OA · Infosys SP
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 x = 1221, rev = 0
while (x > rev)
rev = rev * 10 + x mod 10
x = x / 10
end while
Print x, rev, (x == rev OR x == rev / 10)- A. 12 12 true
- B. 1221 1221 true
- C. 1 122 false
- D. 122 1 false
Correct answer: A. 12 12 true
Only half the number is reversed: (x, rev) goes (122, 1) → (12, 12), and the loop stops since x is no longer greater than rev. 12 == 12, so it is a palindrome: 12 12 true.
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) Integer fact[10], count = 0…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer n = 50, c = 0, p = 2…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer n = 36, s = 0 for…
- What will be the output of the following pseudocode? (& is bitwise AND) Integer mask = 13, s, c = 0 s = mask while (s > 0) c = c + 1 s =…
- What will be the output of the following pseudocode? (integers are 32-bit; & is AND, << and >> are shifts) Integer x = 45 Integer y = (x…
- What will be the output of the following pseudocode? // BST: smaller keys go left, larger (or equal) keys go right Insert into an empty…