What will be the value of i in the next pseudocode?

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

Consider the following pseudocode.
x: = 1;
i: = 1;
whereas (x> = 1000)
start
x: = 2 ^ x;
i: = i + 1;
end;


What is the value I am at the end of the pseudocode?


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

I'm sure there i

will be value 1

. I told the examiner about the discrepancy and he advised me to leave the question unanswered if I felt it was not correct. What else could I do?

+2


source to share


4 answers


1

X <1000 so it doesn't enter time.

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



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

2 - 4 - 16 - 65K

2 - 3 - 4 - 5

+1


source


This question checks two things:

  • can you read the code
  • You can chat / interact

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



I suppose I would leave a note on the answer sheet that says "none of the data".

Not an easy situation!

+1


source


As written, the answer is 1.

If the test was for what was reversed (i.e. x <1000) then the series:

At the end of each loop iteration

i = 2, x = 2
i = 3, x = 2 ^ 2 = 4
i = 4, x = 2 ^ 4 = 16
i = 5, x = 2 ^ 16 = 65,536

So I would be 5

+1


source


If I am where you are, I would say 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 never changes. I think it's a bad assignment to leave blank answers in the quiz, it's always best to write what you think matters. If you think there is a bug, you can always specify a guess before quoting your answer, so in this case, you can say that the while loop never works, otherwise you explicitly state a guess, in which case it is something like " Assuming there is a mistake in the question, and that "while (x> = 1000)" should actually be "while (x <= 1000)" ... Then you will continue your work.

0


source







All Articles