ProgrammingHardTCS NQT Advanced · Infosys SP
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer n = 3524, steps = 0
while (n != 6174)
Integer big = digits of n sorted in decreasing order (4 digits, zeros kept)
Integer small = digits of n sorted in increasing order
n = big - small
steps = steps + 1
end while
Print steps- A. 1
- B. 3
- C. 2
- D. 7
Correct answer: B. 3
Kaprekar's routine: 5432 − 2345 = 3087; 8730 − 0378 = 8352; 8532 − 2358 = 6174. Three steps.
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 total = 0, n for (each…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division; + joins strings) Function…
- What will be the output of the following pseudocode? Integer m[3][3] = {{1, 2, 3}, {2, 5, 9}, {4, 6, 0}} Integer bad = 0 for (each i from…
- What will be the output of the following pseudocode? (operands are evaluated strictly left to right) Integer a = 7, b = 3 a = a + b - (b =…
- What will be the output of the following pseudocode? Integer calls = 0 Function C(Integer n, Integer k) calls = calls + 1 if (k == 0 OR k…
- What will be the output of the following pseudocode? // Integer16: 16-bit signed integers in two's complement; results wrap around…