In [1]:
r = int (input("Enter the number of rows of the matrix: "))
c = int(input("Enter the number of columns of the matrix: "))
print("Enter the elements of the matrx: ")
A = []
for i in range(0, r):
row = []
for j in range(0, c):
row.append(int(input()))
A.append(row)
print ('The entered matrix is: ')
for i in range(0, r):
for j in range(0, c):
print (A[i][j], end = " ")
print()
print ('Sum of main diagonal elements of the matrix is: ')
sum = 0
for i in range(0, r):
sum = sum + A[i][i]
print (sum)
Enter the number of rows of the matrix: 3 Enter the number of columns of the matrix: 3 Enter the elements of the matrx: 3 4 5 4 5 6 5 6 7 The entered matrix is: 3 4 5 4 5 6 5 6 7 Sum of main diagonal elements of the matrix is: 15
No comments:
Post a Comment