CBSE Class 11 Informatics Practices Question 36 of 36

Conditional and Looping Constructs — Question 36

Back to all questions
36
Question

Question 18(c)

WAP to print the following pattern:

1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
Solution
n = 5

for i in range(1, n + 1):
    for j in range(i, 0, -1):
        print(j, end=" ")
    print()
Output
1 
2 1
3 2 1
4 3 2 1
5 4 3 2 1
Answer

n
=
5
for
i
in
range
(
1
,
n
+
1
):
for
j
in
range
(
i
,
0
,
-
1
):
print
(
j
,
end
=
" "
)
print
()
Output
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1