19,107 views
10 10 votes

Consider the following pseudo-code

x:=1;
i:=1;
while (x <= 1000)
begin
    x:=2^x;
    i:=i+1;
end;

What is the value of i at the end of the pseudo-code?

  1. 4
  2. 5
  3. 6
  4. 7

3 Answers

Best answer
13 13 votes
1st time ... x = 2 and i = 2

2nd time ...x=4 and i=3

3rd time.....x=16 and i = 4

4th time ......before entering the loop value of x < 1000 ....it is 16 so it will enter the loop

and make i = 5

5th time x>1000 so while loop doesn't execute.....

SO the answer is i = 5
selected by
4 4 votes
initialy 1st itr.. 1<=1000(true) 2nd itr..  2<=1000(true) 3rd itrn  ..4<=1000(true) 4th itrn   16<=1000(true)
x=1 x=2 x=4 x=16 x=>1000
i=1 i=2 i=3 i=4 i=5

then in the next iteration while loop will be false

and value of i=5.

B is the ans

Answer:
Position:
Show:

Related questions

61 61 votes
5 answers 5 answers
14.5k
14.5k views
Kathleen asked Sep 17, 2014
14,484 views
A program consists of two modules executed sequentially. Let $f_1(t)$ and $f_2(t)$ respectively denote the probability density functions of time taken to execute the two ...
6 6 votes
4 answers 4 answers
5.7k
5.7k views
go_editor asked Jun 10, 2016
5,721 views
Which of the following programming language(s) provides garbage collection automaticallyLispC++FortanC
14 14 votes
3 answers 3 answers
7.1k
7.1k views
go_editor asked Jun 10, 2016
7,134 views
Djikstra&rsquo;s algorithm is used toCreate LSAsFlood an internet with informationCalculate the routing tablesCreate a link state database
7 7 votes
3 3 answers
6.3k
6.3k views
go_editor asked Jun 10, 2016
6,312 views
Which of the following models used for software reliabilityWaterfallMusaCOCOMORayleigh