Open In App

Capgemini | Pseudocode Questions | Question 3

Predict the output of the following pseudocode.

Integer value, n
Set value = 1, n = 45
while(value less than equal to n)
  value = value << 1
end loop
Print value

(A)



16

(B)



32

(C)

64

(D)

36

Answer: (C)
Explanation:

Firstly variables n and value are initialized, then n and value are assigned values 45 and 1 respectively.
Now run a while loop will until the value becomes greater than 45, in each iteration of the loop perform a left shift by 1(multiply by 2) operation on the value variable.

Thus the value changes in order 1, 2, 4, 8, 16, and 32 till here the value is less than 45 then again perform the operation value << 1, value = 64 and the while loop terminates.

Quiz of this Question
Please comment below if you find anything wrong in the above post

Article Tags :
Uncategorized