ProgrammingModerateTCS NQT · Accenture pattern
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer v = 1
for (k = 0 to 4)
v = v * 2 + k
end for
Print v- A. 58
- B. 32
- C. 57
- D. 42
Correct answer: A. 58
v: 1 → 2 → 5 → 12 → 27 → 58 (k = 0..4). Ignoring the + k gives 2⁵ = 32. Each step doubles the accumulated value, so earlier k contribute more.
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 calls = 0 Integer Function f(Integer n) calls = calls + 1 if (n <= 2) return…
- What will be the output of the following pseudocode? Integer a = 5, b, c, d b = a++ // post-increment c = ++a // pre-increment d = a + b +…
- What will be the output of the following pseudocode? Integer a[5] = {2, 4, 6, 8, 10} for (i = 1 to 4) a[i] = a[i] + a[i - 1] end for Print a
- What will be the output of the following pseudocode? Integer x = 1 for (i = 1 to 4) if (i mod 2 == 1) x = x i else x = x + i end if end…
- What will be the output of the following pseudocode? Integer n = 10, s = 0 for (i = 1 to n) if (n mod i == 0) s = s + i end if end for…
- What will be the output of the following pseudocode? Integer Function f(Integer x, Integer y) if (x > y) return f(x - y, y) if (x < y)…