15,780 views
8 votes
8 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
11 votes
11 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 votes
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:

Related questions

5 votes
5 votes
4 answers
1
go_editor asked Jun 10, 2016
3,870 views
Which of the following programming language(s) provides garbage collection automaticallyLispC++FortanC
13 votes
13 votes
3 answers
2
go_editor asked Jun 10, 2016
5,097 views
Djikstra&rsquo;s algorithm is used toCreate LSAsFlood an internet with informationCalculate the routing tablesCreate a link state database
5 votes
5 votes
3 answers
3
go_editor asked Jun 10, 2016
4,892 views
Which of the following models used for software reliabilityWaterfallMusaCOCOMORayleigh
3 votes
3 votes
3 answers
4
go_editor asked Jun 10, 2016
5,952 views
In UML diagram of a classstate of object cannot be representedstate is irrelevantstate is represented as an attributestate is represented as a result of an operation