Discussion
Consider the following pseudocode:
x:=1;
i:=1;
while (x ≤ 500)
begin
x := 2^x ;
i:=i+1;
end
What is the value of i at the end of the pseudocode?
Answer: B
Correct answer: 5
Each pass replaces x by \(2^x\), which grows extremely fast:
| after pass | - | 1 | 2 | 3 | 4 |
|---|---|---|---|---|---|
| x | 1 | 2 | 4 | 16 | 65536 |
| i | 1 | 2 | 3 | 4 | 5 |
The test \(x \le 500\) fails once x reaches 65536, and i is then 5.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development