ProgrammingModerateCapgemini · Infosys pattern
What will be the output of the following pseudocode? (Arrays are indexed from 0.)
What will be the output of the following pseudocode? (Arrays are indexed from 0.)
Integer arr[6] = {1, 2, 3, 4, 5, 6}
for (each i from 0 to 2)
swap(arr[i], arr[5 - i])
end for
Print arr[0], arr[2], arr[5]- A. 6 5 1
- B. 6 3 1
- C. 6 4 1
- D. 1 3 6
Correct answer: C. 6 4 1
Swapping the pairs (0, 5), (1, 4) and (2, 3) reverses the array to {6, 5, 4, 3, 2, 1}. So arr[0] = 6, arr[2] = 4, arr[5] = 1.
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 x = 1 while (x < 100) x = x 3 end while Print x
- What will be the output of the following pseudocode? Integer s = 0 for (i = 10; i >= 1; i = i - 3) s = s + i end for Print s
- What will be the output of the following pseudocode? Integer c = 0 for (each d from 1 to 36) if (36 mod d == 0) c = c + 1 end if end for…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division.) Integer a = 15, b = 4 Print…
- What will be the output of the following pseudocode? Integer a = 5, b = 0 if (a > 3 && b != 0) Print "X" else if (a > 3 || b > 0) Print…
- What will be the output of the following pseudocode? Function fun(Integer n) if (n < 3) return n end if return fun(n - 1) + 2 fun(n - 3)…