Skip to content

令和4年度 ITパスポート試験 問79

This question's explanation and your answers so far.

問79
頻出度★★☆

流れ図で示す処理を終了したとき,x の値はどれか。 開始 ↓ x を 98 とする ↓ y を 42 とする ↓ 繰返し(x = y)(注) ↓ (分岐)x : y  ・「>」の場合: x - y の計算結果を新たな x とする  ・「≦」の場合: y - x の計算結果を新たな y とする ↓ 繰返し ↓ 終了 (注)ループ端の条件は,終了条件を示す。

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

問 79

  • Incorrectア

    x never becomes 0. This process is not a procedure that reduces a division remainder to 0; it is a subtractive algorithm that repeatedly subtracts the smaller value from the larger one until the two are equal, so it stops at the GCD 14 and never reaches 0.

  • イ

    正解 This flow diagram is a process that finds the greatest common divisor (GCD) of 98 and 42 using the Euclidean algorithm with subtraction only. According to the Note, the loop ends when x = y. In the branch x : y, when x > y it assigns x - y to x, and when x ≦ y it assigns y - x to y. Tracing step by step from x = 98 and y = 42: first 98 > 42, so x = 98 - 42 = 56; next 56 > 42, so x = 56 - 42 = 14; then 14 ≦ 42, so y = 42 - 14 = 28; then 14 ≦ 28, so y = 28 - 14 = 14, at which point x = y (14 = 14) holds and the process ends. Therefore the value of x at termination is 14, so answer イ is correct.

  • Incorrectウ

    28 is a value assigned to y along the way (42 - 14 = 28), not the value of x that is being asked. Moreover, the process does not end here; it continues further to y = 28 - 14 = 14.

  • Incorrectエ

    56 is merely an intermediate value assigned to x in the first calculation (98 - 42 = 56). At this point x = y has not yet been reached, so the loop does not end and this is not the final value.

ここがポイント
  • The Note attached to the loop boundary (loop) indicates the termination condition. The premise is to correctly grasp the reading that the loop is exited once x = y holds.
  • This question uses the subtractive Euclidean algorithm, repeating the operation of subtracting the smaller value from the larger one to find the GCD 14 of 98 and 42. The key point is to carefully trace the branch and assignment one step at a time from the initial values.
用語

Your answers