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
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
.................
'''
Comments
Leave a comment