ProgrammingHardTCS NQT · Accenture pattern
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer a = 1, b = 2, c = 3 a = (a < b) ? b : c b = (b < c AND a == 2) ? c : a c = (a > b OR c > a) ? a + b : 0 Print a, b, c
- A. 2 3 5
- B. 2 2 4
- C. 3 3 6
- D. 2 3 0
Correct answer: A. 2 3 5
a < b, so a = 2. Then b < c and a == 2, so b = c = 3. Finally a > b is false but c (3) > a (2) is true, so c = a + b = 5. Each line uses the values updated by the previous lines.
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 h(Integer n) if (n <= 0) return 1 if (n mod 2 == 1) return h(n - 1)…
- What will be the output of the following pseudocode? Integer v = 0 for (i = 1 to 5) v = (v << 1) | (i & 1) end for Print v
- What will be the output of the following pseudocode? Integer a[] = {10, 20, 30, 40} Integer i = 0, s = 0 while (i < 4) s = s + a[i] i = i…
- What will be the output of the following pseudocode? (memo starts with every entry equal to −1; calls counts every call, including the…
- What will be the output of the following pseudocode? (calls counts every call, including the first.) Integer calls = 0 Function g(Integer…
- What will be the output of the following pseudocode? (& is bitwise AND and >> is a right shift.) Integer c = 0 for (each x from 1 to 200)…