Consider the following pseudocode:
x:=1; i:=1; while (x ≤ 500) begin x:=2x ; i:=i+1; end
What is the value of i at the end of the pseudocode?
Explanation: The program executes as:
In iteration 1: x = 2 and i = 2 In iteration 2: x = 4 and i = 3 In iteration 3: x = 16 and i = 4 In iteration 4: x = 16*16 and i = 5 In iteration 5: Condition incorrect.
So, option (B) is correct.
Quiz of this Question
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.