Examly題庫立即開始練習
地方政府公務人員四等-電子工程類科計算機概要10815單選題

執行下列 C 語言程式的結果為何? #include<stdio.h> int unknown(int temp[], int size, int key) { int i = 0; while( (temp[i] != key) && (i < size)) i++; return(i); } void main(){ int list[]={1,3,5,7,9,11,13,15}; int output =unknown(list, 8, 3); printf("%d", output); }

題目附圖
A輸出整數 1正確答案
B輸出整數 3
C輸出整數 8
D進入無窮迴圈程式無法停止
答案與詳解
A
正確答案
Sequential Search線性搜尋,找到key=3在陣列index=1的位置,回傳索引值1

為什麼答案是 A

i=0時temp[0]=1≠3且0<8,進迴圈i++→i=1;i=1時temp[1]=3=key,條件temp[i]!=key為false,while結束,return(1),printf輸出1

考點:線性搜尋回傳索引考點:索引vs.值混淆考點:找不到時才回傳size考點:迴圈終止條件
載入中…

計算機概要 相關題目

想練更多計算機概要考古題?

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

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