138. Python Program to print Inner Square elements of a given matrix.
How does this program work?
- In this program we are going to learn about how to print Inner Square elements of a given matrix using Python.
- Elements are stored in array variable. Here we used 4*4 matrix to display inner square 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("Output: ")
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("Inner Square of a matrix: ")
k = n-1
if (k > n):
print()
for i in range(n - k+1):
for j in range(n - k+1 ):
print(a[i+1][j+1], end = " ")
print()