ProgrammingHardCapgemini · Infosys pattern
What will be the output of the following pseudocode? (Matrices are indexed from 0.)
What will be the output of the following pseudocode? (Matrices are indexed from 0.)
Integer mat[3][2] = {{1, 2}, {3, 4}, {5, 6}}
Integer total = 0
for (each i from 0 to 2)
for (each j from 0 to 1)
total = total + mat[i][j]
end for
end for
Print total- A. 15
- B. 18
- C. 21
- D. 12
Correct answer: C. 21
Every one of the 6 entries of this 3x2 matrix is visited exactly once and summed: 1+2+3+4+5+6 = 21.
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 (merging two sorted arrays)? (Arrays are indexed from 0.) Integer a[4] = {1, 3, 5, 7}…
- What will be the output of the following pseudocode? Integer c = 0, n = 5 for (each i from 1 to n) for (each j from 1 to 2 i - 1) c = c +…
- What will be the output of the following pseudocode? (Arrays are indexed from 0.) Integer arr[6] = {4, 8, 15, 16, 23, 42} Integer target =…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division.) Function countDigits(Integer…
- What will be the output of the following pseudocode (Pascal's identity for combinations)? Function C(Integer n, Integer r) if (r == 0 or r…
- What will be the output of the following pseudocode (Armstrong number check)? Function isArmstrong(Integer n) String s = toString(n)…