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

執行下列 C 程式,並輸入「10 10 9」,下列何者為程式的輸出? #include <stdio.h> #include<iostream> int main() { int count =0, x=10, next; scanf("%d", &next); while (next == x) { count++; scanf("%d", &next); } printf("%d", count); }

A2正確答案
B3
C9
D10
答案與詳解
A
正確答案
while 迴圈判斷 next==10,輸入前兩個 10 各加一次,第三次讀到 9 跳出,count=2。

為什麼答案是 A

初始 count=0,先讀第一個 next=10,進入迴圈 count=1;再讀 10,count=2;再讀 9,條件不成立跳出,印出 2。

考點:while 計數考點:迴圈順序陷阱考點:變數混淆
載入中…

計算機概要 相關題目

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

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

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