ProgrammingModerateAccenture · Cognizant pattern
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer a = 10, b = 20, c = 30, r
if (a > b AND b > c)
r = 1
else if (a < b OR c < b)
r = 2
else
r = 3
end if
a = a + b
b = a - b
c = c - a
Print r, a, b, c- A. 2 30 20 0
- B. 2 30 10 0
- C. 3 30 10 0
- D. 2 30 10 -30
Correct answer: B. 2 30 10 0
a < b is true, so r = 2. Then a = 30, b = 30 − 20 = 10 (the old a), c = 30 − 30 = 0, because c uses the updated a.
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 Function f(Integer n) if (n == 1) return 1 return f(n / 2) + n // integer…
- What will be the output of the following pseudocode? Integer count = 0 for (i = 2 to 30) Boolean prime = true for (d = 2 while d d <= i)…
- What will be the output of the following pseudocode? Integer a[6] = {1, 2, 3, 4, 5, 6}, n = 6 for (i = 0 to n/2 - 1) swap(a[i], a[n - 1…
- What will be the output of the following pseudocode? // C-style integer arithmetic: / truncates toward zero, mod keeps the dividend's sign…
- What will be the output of the following pseudocode? Integer Function g(Integer n) if (n <= 1) return n return g(n - 1) + 2 g(n - 2) End…
- What will be the output of the following pseudocode? String s = "" Integer n = 13 while (n > 0) s = (n mod 2) + s // prepend the digit n =…