Program-5

Write a program to convert the given square matrix into a lower triangular matrix.

n=int(input("Enter the order of matrix: "))
mat=[]
print("Enter values for matrix: ")
for i in range(1,n+1):
a=[]
for j in range(1,n+1):
print("Entry in row: {} column: {}".format(i,j))
a.append(int(input()))
mat.append(a)
print("The given matrix is: ")
for i in range(n):
for j in range(n):
print(mat[i][j],end=" ")
print()
print("Lower Triangular matrix: ")
for i in range(n):
for j in range(n):
if i<j:
print(0,end=" ")

else:
print(mat[i][j],end=" ")

if i<=n-1:
print()


Sample Input and Output:

Enter the order of matrix: 3 Enter values for matrix: Entry in row: 1 column: 1 1 Entry in row: 1 column: 2 2 Entry in row: 1 column: 3 3 Entry in row: 2 column: 1 4 Entry in row: 2 column: 2 5 Entry in row: 2 column: 3 6 Entry in row: 3 column: 1 7 Entry in row: 3 column: 2 8 Entry in row: 3 column: 3 9 The given matrix is: 1 2 3 4 5 6 7 8 9 Lower Triangular matrix: 1 0 0 4 5 0 7 8 9

No comments:

Post a Comment