Skip to content

令和3年度 ITパスポート試験 問74

This question's explanation and your answers so far.

問74
頻出度★★☆

流れ図Xで示す処理では,変数 i の値が,1→3→7→13と変化し,流れ図Yで示す処理では,変数 i の値が,1→5→13→25と変化した。図中の a,b に入れる字句の適切な組合せはどれか。 〔流れ図X〕 開始 → i に1を格納する → 変換(ループ端) k:1,1,3 (注) → [ a ]を計算し,その結果を i に格納する → 変換(ループ端) → 終了 〔流れ図Y〕 開始 → i に1を格納する → 変換(ループ端) [ b ] (注) → [ a ]を計算し,その結果を i に格納する → 変換(ループ端) → 終了 (注)ループ端の繰返し指定は,変数名:初期値,増分,終値を示す。

出典 令和3年度 ITパスポート試験 問74
解説

問 74

  • Incorrectア

    a=2i+k is wrong. Checking in flow diagram X: the 1st pass gives 2×1+1=3, which matches, but the 2nd pass gives 2×3+2=8, which disagrees with the actual value 7. Since the expression for a already fails to hold, this option is inappropriate. b=k:1,3,7 is also wrong, as described below.

  • Incorrectイ

    b=k:2,2,6 is correct, but a=2i+k is wrong. As with option ア, the 2nd pass in flow diagram X gives 2×3+2=8 instead of 7. Since a does not match, the option as a whole is inappropriate.

  • Incorrectウ

    a=i+2k is correct, but b=k:1,3,7 is wrong. It specifies looping k with initial value 1, increment 3, final value 7, that is, k=1,4,7. Substituting into the 1st pass of flow diagram Y gives 1+2×1=3, not the actual value 5. Since Y cannot be reproduced, this option is inappropriate.

  • エ

    正解 First determine a from flow diagram X. In X, the initial value of i is 1, and the loop terminal specifies k:1,1,3 (k has initial value 1, increment 1, final value 3), so it loops 3 times with k=1,2,3. Substituting a=i+2k on each pass: 1st pass 1+2×1=3, 2nd pass 3+2×2=7, 3rd pass 7+2×3=13, which exactly matches the change of i, namely 1→3→7→13. Therefore a=i+2k. Next, determine b from flow diagram Y. Y uses the same a=i+2k, and i changes as 1→5→13→25. Working backward to find the k needed for each transition: for 1→5, from 5=1+2k we get k=2; for 5→13, k=4; for 13→25, k=6. Thus k increases from 2 by steps of 2 up to 6, that is, b=k:2,2,6. The only option satisfying both a=i+2k and b=k:2,2,6 is エ.

ここがポイント
  • How to read the loop terminal iteration specification of the form 'variable name: initial value, increment, final value'. For example, k:2,2,6 means looping k from 2, increasing by 2 each time up to 6, so it represents 3 passes with k=2,4,6.
  • A technique for working backward from a sequence of value changes to an expression or parameters. Substitute each candidate expression into the known transitions (previous i → next i), verify, and keep only the one that matches on every pass.
用語

Your answers