The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+3 votes
1.6k 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
asked in Algorithms by Veteran (96.1k points) | 1.6k views

4 Answers

+3 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

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

ans is (b)

answered by Active (4.7k points)
+2 votes
answer is 4
answered 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
answered by (11 points)
Answer:

Related questions

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
49,541 questions
54,083 answers
187,208 comments
70,992 users