ProgrammingVery hardWipro NLTH · Cognizant GenC
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
List L = [1, 2, 3, 4, 5, 6, 7]
Integer idx = 0, k = 3
while (size(L) > 1)
idx = (idx + k - 1) mod size(L)
remove the element at position idx from L
end while
Print L[0]- A. 1
- B. 5
- C. 7
- D. 4
Correct answer: D. 4
Removals in order: 3, 6, 2, 7, 5, 1, leaving 4. (After each removal idx already points at the next element.)
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? Function gcd(Integer a, Integer b) while (b != 0) t = a mod b a = b b = t end while…
- What will be the output of the following pseudocode? String s = "{[()]}(()" Stack st Integer pops = 0, i Boolean ok = true for (i = 0; i <…
- What will be the output of the following pseudocode? Integer a[5] = {2, 5, 9, 14, 20}, i for (i = 1; i < 5; i = i + 1) a[i] = a[i] - a[i…
- What will be the output of the following pseudocode? Integer x = 0, i for (i = 1; i <= 10; i = i + 1) x = ((x << 1) ^ i) & 15 end for…
- What will be the output of the following pseudocode? Integer w[5][5], i, j for (i = 0; i < 5; i = i + 1) for (j = 0; j < 5; j = j + 1) if…
- What will be the output of the following pseudocode? String A = "AXYT", B = "AYZX" Integer L[5][5] = all 0, i, j for (i = 1; i <= 4; i = i…