ProgrammingHardTCS NQT · Accenture pattern
What will be the output of the following pseudocode (2x2 matrix multiplication)?
What will be the output of the following pseudocode (2x2 matrix multiplication)?
Integer A[2][2] = {{1, 2}, {3, 4}}
Integer B[2][2] = {{5, 6}, {7, 8}}
Integer C[2][2] = {{0, 0}, {0, 0}}
for (each i from 0 to 1)
for (each j from 0 to 1)
for (each k from 0 to 1)
C[i][j] = C[i][j] + A[i][k] * B[k][j]
end for
end for
end for
Print C- A. [[19, 22], [43, 50]]
- B. [[5, 12], [21, 32]]
- C. [[19, 43], [22, 50]]
- D. [[17, 20], [41, 48]]
Correct answer: A. [[19, 22], [43, 50]]
Standard matrix multiplication: C[0][0]=1*5+2*7=19, C[0][1]=1*6+2*8=22, C[1][0]=3*5+4*7=43, C[1][1]=3*6+4*8=50.
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 (binary string to decimal)? String bits = "110101" Integer val = 0 for (each b in…
- What will be the output of the following pseudocode (finding the 1-based position of the rightmost set bit)? (All variables are integers…
- What will be the output of the following pseudocode (checking if s3 is an interleaving of s1 and s2, via dynamic programming)? Function…
- What will be the output of the following pseudocode (counting pairs (i,j) with i<=j<=n whose product is divisible by n)? Integer n = 12, c…
- What will be the output of the following pseudocode (checking whether all characters in a string are unique)? Function…
- What will be the output of the following pseudocode (Hamming distance: number of differing bits between two integers)? (^ is bitwise XOR…