Machine-translated by Google. Questions are authored in English.
Top

Discussion

Consider the following pseudocode:

x:=1;
i:=1;
while (x ≤ 500)
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

Correct answer: 5

Each pass replaces x by \(2^x\), which grows extremely fast:

after pass-1234
x1241665536
i12345

The test \(x \le 500\) fails once x reaches 65536, and i is then 5.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.