The Gateway to Computer Science Excellence
+4 votes
1.8k views

Consider the following pseudocode

x:=1;

i:=1;

while ( x $\leq$ 500)

begin

x:=2$^x$;

i:=i+1;

end

What is the value of i at the end of the pseudocode?

  1. 4
  2. 5
  3. 6
  4. 7
in Algorithms by | 1.8k views

5 Answers

+5 votes

ans is B  value of i=5  initially x=1<1000 so i becomes 2 then x=2 , i =3 ,then x=4 , i=4 then x=16, i=5 now x=2^16>1000 so exit finally i=5

by
0
Here the condition given is (x<=500), then the answer will be A) 4, Right?
+3 votes

ans is (b)

by
+2 votes
answer is 4
by
+2 votes
$\underline{\textbf{Answer:}\Rightarrow}\mathbf{B)\;5}$

$\underline{\textbf{Explanation:}\Rightarrow}$

$\underline{\text{Step:1}}$

$\mathrm{x = 1,\;i = 1}$

$\underline{\text{Step:2}}$

$\mathrm{x = 2,\;i = 2}$

$\underline{\text{Step:3}}$

$\mathrm{x = 4,\;i = 3}$

$\underline{\text{Step:4}}$

$\mathrm{x = 16,\;i = 4}$

Now, $\mathrm{x = 16}\le500$

$\underline{\text{Step:5}}$

$\mathrm{x = 2^{16},\;i = 5}$

$\therefore \;\mathbf 5$ is the right answer.
by
0 votes
B

because when x =16, the while loop was (16<=500)executed then i= 5 and x=2^16, next  in whlie(2^16<=500) it is false . so ans is 5
by
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
52,315 questions
60,427 answers
201,750 comments
95,226 users