Consider the following psuedocode: x := 1; i := 1; while (x <= 1000) begin x := 2^x; i := i + 1; end; What is the value of i at the end of the pseudocode?
- A. 4
- B. 5
- C. 6
- D. 7
Answer: B. 5
Explanation: i=1, x=1. Loop 1: x=2^1=2, i=2. Loop 2: x=2^2=4, i=3. Loop 3: x=2^4=16, i=4. Loop 4: x=2^16=65536, i=5. Loop 5: x > 1000, terminates. Result i=5.