CBSE Class 11 Computer Science Question 69 of 80

Conditional and Looping Constructs — Question 39

Back to all questions
39
Question

Question 21(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