tags:

views:

114

answers:

4

I got this question in a programming test. Do you think this question is even correct? Look at the answer choices. (2^x means 2 raised to x)

Consider the following pseudocode.
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 pseudocode?

a) 4
b) 5
c) 6
d) 7
e) 8

I am sure that the value of i will 1. I told the examiner of the discrepancy and he advised me the leave the question unanswered if I felt it was incorrect. What else could I have done?

+1  A: 

This question tests two things:

  1. can you read code
  2. can you communicate / interact

Since you asked about the discrepancy, you showed 1. to be true. I'm not so sure if you passed 2, it depends too much on the situation / expectations.

I believe I would have left a note on the answer sheet stating 'none of the given'.

Not an easy situation!

lexu
+1  A: 

1

X < 1000, so it doesn't enter the while.

Or there is an error in the Question (and X should be <= 1000 and not >=1000)

If it's <= 1000 it should be 5:

2 - 4 - 16 - 65K

2 - 3 - 4 - 5

Dani
+1  A: 
Rowland Shaw
A: 

If I where you, I would say that it is none of the above and basically say that since x is less than 1000 when the while loop starts, the value of i is never modified. I think that it is a bad thing to leave blank answers in a quiz, it is always better to write something which you think is relevant. If you think that there is a mistake, you can always state an assumption before stating your answer, so in this case you can either say that the while loop never works, or else, you explicitly state an assumption, in this case, it would be something like "Assuming that there is a mistake in the question, and that "while (x >= 1000)" should in fact be "while (x <= 1000)"... Then, you proceed with your working.

npinti