Sum of opposite/minor diagonal elements of a matrix¶
In [1]:
s = int (input("Enter the size of the matrix: "))print("Enter the elements of the matrx: ")A = []for i in range(0, s): row = [] for j in range(0, s): row.append(int(input())) A.append(row)print ('The entered matrix is: ')for i in range(0, s): for j in range(0, s): print (A[i][j], end = " ") print() print ('Sum of opposite/minor diagonal elements of the matrix is: ')sum = 0for i in range(0, s): for j in range(0, s): if (i + j) == (s - 1): sum = sum + A[i][j] print (sum)Enter the size of the matrix: 3 Enter the elements of the matrx: 3 2 3 4 3 4 5 4 6 The entered matrix is: 3 2 3 4 3 4 5 4 6 Sum of opposite/minor diagonal elements of the matrix is: 11
No comments:
Post a Comment