निम्नलिखित छद्म कोड का आउटपुट क्या होगा?
What will be the output of the following pseudo-code ?
Integer a
Set a = 5
do
print a - 2
a = a- 1
while (a not equals 0)
end while A
5 3 0
B
3 0
C
infinite loop
D
None of these
Explanation
Let's break it down quickly:
- Initial value:
a = 5. - In each loop iteration:
- Prints
a - 2. - Decreases
aby 1.
- Prints
- The loop stops when
abecomes 0.
Iterations:
- First: prints
5 - 2 = 3,abecomes 4. - Second: prints
4 - 2 = 2,abecomes 3. - Third: prints
3 - 2 = 1,abecomes 2. - Fourth: prints
2 - 2 = 0,abecomes 1. - Fifth: prints
1 - 2 = -1,abecomes 0.
The loop stops when a = 0.
Output:
3 2 1 0 -1
So the correct answer is:
(D) None of these
Correct Answer: B) 3 0