निम्नलिखित छद्म कोड का आउटपुट क्या होगा?
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)
B)
C)
D)
Explanation:
Let's break it down quickly:
- Initial value:
a = 5
. - In each loop iteration:
- Prints
a - 2
. - Decreases
a
by 1.
- Prints
- The loop stops when
a
becomes 0.
Iterations:
- First: prints
5 - 2 = 3
,a
becomes 4. - Second: prints
4 - 2 = 2
,a
becomes 3. - Third: prints
3 - 2 = 1
,a
becomes 2. - Fourth: prints
2 - 2 = 0
,a
becomes 1. - Fifth: prints
1 - 2 = -1
,a
becomes 0.
The loop stops when a = 0
.
Output:
3 2 1 0 -1
So the correct answer is:
(D) None of these