137. Python Program to find Upper and Lower trianglular of a given matrix.
How does this program work?
- In this program we are going to learn about how to find Upper and Lower trianglular of a given matrix using Python.
- Elements can be stroed in variable using arrays.
- After that by using the forloop condition we find the Upper elements and Lower elements of given matrix.
Here is the code
a=[]
n=int(input("Enter the size of the matrix: "))
print("Enter the elements: ")
for i in range(n):
row=[]
for j in range(n):
row.append(int(input()))
a.append(row)
print(a)
print("Display an array In Matrix Form: ")
for i in range(n):
for j in range(n):
print(a[i][j], end=" ")
print()
print("Lower triangular matrix: ")
for i in range(0, n):
for j in range(0, n):
if (i < j):
print(end = " ")
else:
print(a[i][j], end=" ")
print (" ")
print("Upper triangular matrix: "))
for i in range(0, n):
for j in range(0, n):
if (i > j):
print(end = " ")
else:
print(a[i][j], end=" ")
print (" ")