ProgrammingModerateAccenture · TCS NQT
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer a[8] = {3, 1, 4, 1, 5, 9, 2, 6}
Integer best = a[0], c = 1
for (each i from 1 to 7)
if (a[i] > best)
best = a[i]
c = c + 1
end if
end for
Print c, best- A. 5 9
- B. 3 9
- C. 4 9
- D. 6 9
Correct answer: C. 4 9
c counts the values larger than everything before them (records): 3, 4, 5, 9. So c = 4 and best = 9.
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 a[6] = {100, 4, 200, 1, 3, 2} Set s = all values of a Integer best = 0, len…
- What will be the output of the following pseudocode? (Arrays are indexed from 0) Integer m[4][4] = {{1, 4, 7, 11}, {2, 5, 8, 12}, {3, 6…
- What will be the output of the following pseudocode? Integer a[7] = {4, 5, 2, 10, 8, 6, 9} Stack st = empty for (each i from 0 to 6) while…
- What will be the output of the following pseudocode? (+ joins strings) Queue q = {"1"} Integer k = 0 String s while (k < 6) s = dequeue(q)…
- What will be the output of the following pseudocode? Integer a[6] = {1, 2, 1, 3, 2, 1} Map cnt = empty Integer pairs = 0 for (each i from…
- What will be the output of the following pseudocode? Integer move = 0 Procedure hanoi(Integer n, Char a, Char b, Char c) if (n == 0)…