ProgrammingModerateTCS NQT · Accenture
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer a[5] = {1, 5, 3, 4, 2}, k = 2, c = 0
for (each i from 0 to 4)
for (each j from i + 1 to 4)
if (a[i] - a[j] == k OR a[j] - a[i] == k)
c = c + 1
end if
end for
end for
Print c- A. 3
- B. 2
- C. 6
- D. 4
Correct answer: A. 3
Each unordered pair is checked once: (1, 3), (5, 3) and (4, 2) differ by 2. c = 3.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What is the time complexity of the following pseudocode, as a function of n? for (each i from 1 to n) for (each j from 1 to i i) if (j mod…
- What is the extra space (memory) used by the following recursive pseudocode as a function of n, counting the call stack? Function…
- What will be the output of the following pseudocode? Integer pas[0..6][0..6] = all 0 for (each i from 0 to 6) pas[i][0] = 1 for (each j…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer a[8] = {4, 9, 1, 7, 3…
- What will be the output of the following pseudocode? Integer c = 0 for (each a from 1 to 20) for (each b from a to 20) for (each h from b…
- What will be the output of the following pseudocode? String s = "Tcs NQT 2024 Exam!" Integer v = 0, c = 0, d = 0, o = 0 for (each ch in s)…