In PYTHON (Sum the major diagonal in a matrix) Write a function that sums all the numbers of the major diagonal in an n × n matrix of integers using the following header: def sumMajorDiagonal (m): The major diagonal is the diagonal that runs from the top left corner to the bottom right corner in the square matrix. Write a test program that reads a 4 × 4 matrix and display the sum of all its elements on the major diagonal. Program Sample Run (With Input Shown in Bold) Enter a 4-by-4 matrix row 0: 1 2 3 4 Enter a 4-by-4 matrix row 1: 5 6.5 7 8 Enter a 4-by-4 matrix row 2: 9 10 11 12 Enter a 4-by-4 matrix row 3: 13 14 15 16 Sum of the elements in the major diagonal is 34.5
In PYTHON (Sum the major diagonal in a matrix) Write a function that sums all the numbers of the major diagonal in an n × n matrix of integers using the following header:
def sumMajorDiagonal (m):
The major diagonal is the diagonal that runs from the top left corner to the bottom right corner in the square matrix. Write a test program that reads a 4 × 4 matrix and display the sum of all its elements on the major diagonal.
Program Sample Run (With Input Shown in Bold)
Enter a 4-by-4 matrix row 0: 1 2 3 4
Enter a 4-by-4 matrix row 1: 5 6.5 7 8
Enter a 4-by-4 matrix row 2: 9 10 11 12
Enter a 4-by-4 matrix row 3: 13 14 15 16
Sum of the elements in the major diagonal is 34.5

Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images









