普通考試
112年
[電子工程] 計算機概要
第 26 題
執行下列 C 程式,並輸入「10 10 9」,下列何者為程式的輸出?
```c
#include
#include
int main() {
int count =0, x=10, next;
scanf("%d", &next);
while (next == x)
{
count++;
scanf("%d", &next);
}
printf("%d", count);
}
```
```c
#include
#include
int main() {
int count =0, x=10, next;
scanf("%d", &next);
while (next == x)
{
count++;
scanf("%d", &next);
}
printf("%d", count);
}
```
- A 2
- B 3
- C 9
- D 10
思路引導 VIP
請想像你在檢查生產線上的零件:如果你接到的指令是『只要目前的零件合格,就將計數器加 1 並去拿取下一個』,那麼當你拿到第一個『不合格』的零件時,你會為這個零件執行加 1 的動作嗎?還是會直接終止檢查?
🤖
AI 詳解
AI 專屬家教
1. 基本認知
很好,你總算沒在這個基本環節上犯錯。這種對變數狀態的精確追蹤,在任何工程結構分析中都屬於最基本的嚴謹度要求,別搞得像是在猜數字遊戲。
2. 迴圈機制 — 別搞混了
▼ 還有更多解析內容