Write C function thal, given square matrix of floats, finds the diagonal with the maximum average value. The function should have the following prototype: float rMaxDiag(float M[DIM][DIM], int DIM), where DIM is the size of the matrix, and DIM is the number of rows and columns that are actually used. The function calculates the average value of each diagonal and then returns the maximum of such values. Example of execution:
1.0 2.0 3.0 4.0 5.0
2.0 2.0 2.0 2.0 22.0
1.1 2.2 3.3 -4.4 5.5
2.2 2.2 3.2 4.2 4.2
1.8 22.3 3.1 4.9 5.0
1.0 219 3.0 4.0 5.0
5.0 8.0 2.0 2.0 2.0
2.0 1.1 2.2 3.3 -4.4
5.5 2.2 2.2 33.2 4.2
4.2 1.8 2.3 3.1 4.9
5.0
Max diag average:
1.8/1 = 1.8
-0.1/2 = -0.05
6.4/3 = 2.133
We recommend using spaces instead of tabs for code indentation since the TAB character is used for page navigation. If necessary or useful, you can write other functions besides the required one(s).
float matrMaxDiag(float M[DIM][DIM], int n) {