ITPEC FE Morning April 2018 Question 6

There is a two-dimensional integer array A whose (i, j)-th element A[i, j] is 2 × i + j. What is the value of the element A[A[1, 1] × 2, A[2, 2] + 1]?

Explanation

19 — work out the inner elements first, then use them as the indices of the outer element.

  • •A[1, 1] = 2 × 1 + 1 = 3
  • •A[2, 2] = 2 × 2 + 2 = 6
  • •Row index: A[1, 1] × 2 = 3 × 2 = 6
  • •Column index: A[2, 2] + 1 = 6 + 1 = 7
  • •A[6, 7] = 2 × 6 + 7 = 19

Answer (d)

Why not others:

  • •(a) 12 — only 2 × i = 2 × 6; the column index j = 7 is never added
  • •(b) 13 — 6 + 7, adding the two indices without doubling the row index
  • •(c) 18 — A[6, 6] = 12 + 6; the + 1 in the column index is left out

Key rule: Evaluate nested subscripts from the inside out, and apply the element formula only after both indices are known.

Algorithm and Programming · AI-written, may contain errors

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.