IPA FE Subject B 2026 Question 1

A question IPA Japan published in 令和8年度 基本情報技術者試験 科目B 公開問題 問1, translated into English. ITPEC is based on the same exams.

From the answer group below, select the correct answer to be inserted into blank in the program. Here, the array index starts at 1.

The following program moves the value of the last element of the integer-type array data to the first element. In doing so, the value of each element other than the last one is moved to the element one position after it.

[Program]
integer []: data ← {1, 2, 3, 4, 5, 6, 7, 8, 9}
integer: top, i
integer: len ← the number of elements in data
top ← data[len]
for (blank)
data[i] ← data[i - 1]
endfor
data[1] ← top

Answer group

Explanation

Decrease i from len down to 2 — the values move one place toward the end, so the copying must start at the end or each value is overwritten before it is copied.

top saves the last value, data[9] = 9. The loop body copies data[i - 1] into data[i], so i must cover positions 9 down to 2: position 9 takes 8, position 8 takes 7, and so on until position 2 takes 1. Going downward, every data[i - 1] is read before anything has overwritten it. Finally data[1] ← top puts 9 at the front, giving {9, 1, 2, 3, 4, 5, 6, 7, 8}.

Answer (d)

Why not others:

  • •(a) and (b) — run upward: data[2] takes 1, then data[3] takes the already-overwritten data[2], so 1 spreads through the array; (b) ends with {9, 1, 1, 1, 1, 1, 1, 1, 1}
  • •(c) — runs downward but starts at len - 1, so position 9 never takes 8 and keeps 9: {9, 1, 2, 3, 4, 5, 6, 7, 9}

Key rule: To shift elements toward higher indexes in place, loop from the high end down; to shift them toward lower indexes, loop upward.

Array Manipulation · AI-written, may contain errors

This question comes from the past questions IPA Japan publishes, translated into English by ITPEC Practice. ITPEC Practice is an independent study tool and is not affiliated with IPA or ITPEC. See the original paper (PDF) or Report an issue.