Examly題庫立即開始練習
2 類科共用卷
普考-電信工程普考-電子工程
計算機概要11327單選題

執行下列 C 語言程式,則螢幕的輸出為何? #include <stdio.h> int extreme(int *data){ int temp=0; for (int i=0; i<4; i++){ if (temp < data[i]) temp=data[i]; } return temp; } int main() { int input[]= {10, 20, 30, 40}; printf("%d", extreme(input)); }

A1
B4
C10
D40正確答案
答案與詳解
D
正確答案
extreme 函式用迴圈找陣列最大值,輸入 {10,20,30,40} 最大為 40。

為什麼答案是 D

temp 初始 0,依序與 10、20、30、40 比較,每次都更新,最終 temp=40,回傳並印出 40。

考點:索引誤解考點:迴圈次數誤解考點:最小值誤判考點:最大值演算法
載入中…

計算機概要 相關題目

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

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

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