-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLower Triangular Matrix.py
More file actions
56 lines (39 loc) · 1021 Bytes
/
Copy pathLower Triangular Matrix.py
File metadata and controls
56 lines (39 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
Given a N X N square matrix, transform the Matrix into a Lower Triangular Matrix by setting all the elements except the lower triangle as zero.
A Lower triangular matrix is a square matrix (where the number of rows and columns are equal) where all the elements above the diagonal are zero.
Input Format:
The first line of the input contains an integer N which represents the number of rows and the number of columns.
Next N lines represent the elements of the matrix.
Output Format:
Print the Lower Triangular form of the Matrix
Example:
Input:
3
1 -2 3
-2 3 1
3 1 2
Output:
1 0 0
-2 3 0
3 1 2
"""
n=int(input())
q=[]
a=[]
for i in range(n):
q.append(input().split())
for i in range(n):
for j in range(0,i+1):
a.append(q[i][j])
for j in range(i+1,n):
a.append("0")
s=0
for i in range(n):
for j in range(n):
if j!=n-1:
print(a[s],"",end="")
else:
print(a[s],end="")
s+=1
if i!=n-1:
print("")