ProgrammingModerateTCS NQT · Wipro
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 n = 19, steps = 0, s, d
while (n != 1 AND n != 4)
s = 0
while (n > 0)
d = n mod 10
s = s + d * d
n = n / 10
end while
n = s
steps = steps + 1
end while
Print n, steps- A. 4 4
- B. 1 4
- C. 1 3
- D. 1 5
Correct answer: B. 1 4
Sum of squares of digits: 19 → 82 → 68 → 100 → 1. It reaches 1 (a 'happy' number) after 4 steps: 1 4.
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 u[1..10], i2 = 1, i3 = 1, i5 = 1, nx u[1] = 1 for (each k from 2 to 10) nx =…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer n = 50, lo = 0, hi =…
- What will be the output of the following pseudocode? (operands are evaluated left to right; arrays are indexed from 0) Integer q[5], front…
- What will be the output of the following pseudocode? String in = "A+BC-D/E", out = "" Stack st = empty // prec: and / are 2, + and - are 1…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division; heap[k / 2] is the parent of…
- What will be the output of the following pseudocode? Integer table[7] = all -1, probes = 0, h for each key in {50, 700, 76, 85, 92, 73…