ProgrammingHardTCS NQT · Accenture
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 a = 1, b = 100, steps = 0
while (a < b)
a = a * 3
b = b / 2
steps = steps + 1
end while
Print steps, a, b- A. 4 81 6
- B. 2 9 25
- C. 3 27 12
- D. 4 81 3
Correct answer: C. 3 27 12
Track (a, b) after each step: (3, 50), (9, 25), (27, 12). Now a ≥ b, so the loop stops after 3 steps: 3 27 12.
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 a[5] = {7, 7, 5, 7, 6} Integer m1 = -1, m2 = -1 for (each i from 0 to 4) if…
- What will be the output of the following pseudocode? Integer a[5] = {2, 3, 4, 5, 1}, passes = 0, n = 5 Boolean swapped for (each i from 0…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer n = 77, steps = 0, p…
- What will be the output of the following pseudocode? (<< is left shift, | is bitwise OR, & is bitwise AND) Integer x = 0 for (each i from…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer mults = 0 Function…
- What will be the output of the following pseudocode? String s = "(()(()))()" Integer depth = 0, best = 0, pairs = 0 for (each i from 0 to…