中等ICT-ALGO-006

What is the output of this pseudocode? n ← 1; WHILE n < 8; n ← n * 2; END WHILE; OUTPUT n

A. 1
B. 4
C. 16
D. 8✓ 答案

解說

n goes 1, 2, 4, 8. When n is 8 the condition n < 8 is false, so the loop stops and 8 is output. It does not multiply once more to 16.

「演算法與偽代碼」全部 12 題 · 資訊及通訊科技 MCQ 題庫