ProgrammingHardAmazon OA · Infosys SP
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer m[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
for (each i from 0 to 2)
for (each j from i + 1 to 2)
swap(m[i][j], m[j][i])
end for
end for
for (each i from 0 to 2)
swap(m[i][0], m[i][2])
end for
Print m[0][0], m[0][1], m[0][2]- A. 3 6 9
- B. 1 4 7
- C. 9 8 7
- D. 7 4 1
Correct answer: D. 7 4 1
A transpose followed by reversing each row rotates the matrix 90° clockwise. The transposed first row 1 4 7 becomes 7 4 1. Reversing the columns instead gives the anticlockwise result 3 6 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? (C-style for loop: the update i = i + 1 runs after each pass of the body) Integer c =…
- What will be the output of the following pseudocode? (Strings are indexed from 0) String s = "110100" Integer v = 0, p = 1 for (each i…
- What will be the output of the following pseudocode? Boolean mark[2..30] = all false Integer ops = 0, j for (each p from 2 to 30) if (p p…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division; arrays are indexed from 0)…
- What will be the output of the following pseudocode? Stack s1 = empty, s2 = empty Procedure enqueue(Integer x) push(s1, x) End Procedure…
- What will be the output of the following pseudocode? (^ is bitwise XOR) Integer s = 0 for (each i from 0 to 15) s = s + (i ^ 5) end for…