Answer to Question #225342 in Python for saii

Question #225342

Numbered Triangle


You are given an integer N. Print Nrows starting from 1 in

the triangle order as shown in the explanation.


Input

The input contains an integer N

Output

The output should have N lines.

Each of the N lines should have space-separated integers as per the triangle order.


INPUT 1 :

5

OUTPUT 1:

1

2 6

3 7 10

4 8 11 13

5 9 12 14 15


INPUT 2 :

4

OUTPUT 2:

1

2 5

3 6 8

4 7 9 10





1
Expert's answer
2021-08-11T14:12:22-0400
n=int(input())#input number N
dk=0
for i in range(n):
    cur=i+1
    for j in range(dk+1):
        if not j:
            print(i+1,end=' ')
        else:
            print(cur+n-j,end=' ')
            cur=cur+n-j
    dk+=1
    print(end='\n')
    
'''
Example
N=5
1
2 2+5-1=6
3 3+5-1=7 7+5-2=10
4 4+5-1=8 4+5-2=11 11+5-3=13
.................
'''

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS