Question
C++ 8.2: (Sum the major diagonal in a matrix) Write a function that sums all the double values in the major diagonal in an n
C++
8.2: (Sum the major diagonal in a matrix) Write a function that sums all the double values in the major diagonal in an n x n matix of double values using the following header:
const int SIZE = 4;
double sumMajorDiagonal(const double m[][SIZE]);
Write a test progrm that reads a 4x4 matrix and displays the the sum of all its elements on the major diagonal.
Sum the major diagonal in a matrix: Programming Exercise 8.2 on page 327. Additional details:
The size of an array cannot be changed based on user input (dynamic memory allocation), so the matrix should be dimensionsed to the max size ever expected (10 x 10 perhaps).
Prompt user to enter N (the size of the N x N matrix).The program should work for any N >= 2.N should not be used anywhere for matrix dimensions.It is only used in for loops to control user input and printing.Note that a 3x3 matrix is really just using the upper corner of the 10x10 matrix.
Prompt the user to enter the elements in the matrix row-by-row.
Display the NxN matrix.
Display the sum of the elements in the major diagonal.The sum should be displayed from the main function, not from the function sumMajorDiagonal.
Include a printout of the main program and the function.
Include printouts for the test case in the textbook as well as for a 2x2 matrix and a 3x3 matrix.
C++
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started