執行下列 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
答案與詳解
初始 count=0,先讀第一個 next=10,進入迴圈 count=1;再讀 10,count=2;再讀 9,條件不成立跳出,印出 2。
