ProgrammingHardInfosys · Accenture pattern
What will be the output of the following pseudocode? (/ is integer division.)
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 = b - 10
steps = steps + 1
end while
Print steps, a, b- A. 6 64 40
- B. 5 32 50
- C. 7 128 30
- D. 6 32 40
Correct answer: A. 6 64 40
(a, b): (1, 100) → (2, 90) → (4, 80) → (8, 70) → (16, 60) → (32, 50) → (64, 40). After 6 steps a = 64 ≥ b = 40 and the loop stops. '5 32 50' stops one step early (32 < 50 still holds).
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? (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…
- What will be the output of the following pseudocode? (/ is integer division.) Function A(Integer n) if (n <= 1) return n end if return B(n…
- What will be the output of the following pseudocode? (x is an 8-bit unsigned value; & is bitwise AND, | is OR, << and >> are shifts.)…