ProgrammingHardAmazon OA · Capgemini
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 a[5] = {10, 20, 30, 40, 50}, b[5], k = 2, n = 5
for (each i from 0 to n - 1)
b[(i + k) mod n] = a[i]
end for
Print b[0], b[1], b[4]- A. 30 40 20
- B. 10 20 50
- C. 50 10 40
- D. 40 50 30
Correct answer: D. 40 50 30
Each a[i] moves k = 2 places to the right, wrapping round: b = {40, 50, 10, 20, 30}, so the output is 40 50 30. A left shift by 2 would give 30 40 20.
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? (Strings are indexed from 0) String s = "ABBCCCDDDD" Integer best = 0, run = 1 for…
- What will be the output of the following pseudocode? Integer M[2][2] = {{1, 1}, {1, 0}}, R[2][2] = {{1, 0}, {0, 1}}, T[2][2] for (each k…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer s = 0 for (each i from…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer n = 360, d = 2, s = 0…
- What will be the output of the following pseudocode? Integer count = 0, s for (each n from 2 to 500) s = 1 for (each d from 2 to n - 1) if…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer count = 0, n, s, d for…