Examly題庫立即開始練習
司法海巡移民特考計算機大意10833單選題

執行 C 程式 test(3),其回傳值為下列何者? int test(int control) { int g[] = {0,2,4,6}, h[] = {20,40,60,80}; int i, g_length = 4, s = 0; for(i = g_length-1;i >= 0;i--){ if(g[i] < control) break; } while(i >= 0){ s = s + (control-g[i]) * h[i]; control = g[i]; i--; } return s; }

A70
B80正確答案
C90
D100
答案與詳解
B
正確答案
模擬執行:從陣列尾端找第一個g[i]<control的位置,再向前累加(control-g[i])*h[i]並更新control。

為什麼答案是 B

i=1時:s=(3-2)*40=40,control更新為2,i=0;i=0時:s=40+(2-0)*20=40+40=80,i=-1跳出,回傳80。

考點:干擾值考點:迴圈模擬考點:未更新control考點:break位置誤判
載入中…

計算機大意 相關題目

想練更多計算機大意考古題?

Examly 收錄 38 萬+ 道歷屆題目,每題都有像這樣的精選詳解。免費下載,立即開練。

Download on theApp Store即將推出Google Play
黑皮