テクノロジ系 2025年度 問78 ★★★★☆ Hard
手続calcMod3を呼び出したときの出力はどれか。
[プログラム]
○calcMod3()
整数型:totalValue, i
totalValue ← 0
for(i を 1 から 7 まで 1 ずつ増やす)
if(i ÷ 3 の余り が 0 と等しい)
totalValue ← totalValue + i
endif
endfor
totalValue を出力する
English
What is the output when procedure calcMod3 is called?
[Program]
○calcMod3()
Integer: totalValue, i
totalValue ← 0
for (i from 1 to 7, increment by 1)
if (remainder of i ÷ 3 equals 0)
totalValue ← totalValue + i
endif
endfor
output totalValue
မြန်မာ
calcMod3 procedure ကို ခေါ်သောအခါ ထုတ်ပေးသော output မှာ အဘယ်နည်း?
[Program]
○calcMod3()
Integer: totalValue, i
totalValue ← 0
for (i ကို 1 မှ 7 သို့ 1 စီ တိုးသည်)
if (i ÷ 3 ၏ အကြွင်းသည် 0 နှင့် ညီ)
totalValue ← totalValue + i
endif
endfor
totalValue ကို ထုတ်ပြပါ
Correct answer: エ — 9
i を 1 から 7 まで順に実行する。i÷3の余りが0になるのは,i=3(3÷3=1余り0)とi=6(6÷3=2余り0)のときである。totalValueはi=3のとき0+3=3,i=6のとき3+6=9となる。よって出力は9(エ)である。
English
The loop runs i from 1 to 7. The condition (i mod 3 = 0) is true when i=3 (3÷3=1, remainder 0) and i=6 (6÷3=2, remainder 0). totalValue accumulates: 0+3=3 when i=3, then 3+6=9 when i=6. The output is 9 — option エ.
မြန်မာ
loop သည် i ကို 1 မှ 7 ထိလည်ပတ်သည်။ i=3 (3÷3=1၊ အကြွင်း 0) နှင့် i=6 (6÷3=2၊ အကြွင်း 0) တွင် အခြေအနေ (i mod 3 = 0) မှန်ကန်သည်။ totalValue သည် i=3 တွင် 0+3=3 ဖြစ်ပြီး i=6 တွင် 3+6=9 ဖြစ်အောင်စုဆောင်းသည်။ ထွက်ပေါ်မှုမှာ 9 ဖြစ်ပြီး ရွေးချယ်မှု エ ဖြစ်သည်။