Hi. I am a beginner of programming course and i just got anexercise problem.. and need your help.. Here's a question.. Write an algorithm that receives an n x n table(2 dimensionalarray havin n rows and n columns) of real values and returns average of the values on its upper left to lowerright diagonal. I would greatly appreciate your help.... Hi. I am a beginner of programming course and i just got anexercise problem.. and need your help.. Here's a question.. Write an algorithm that receives an n x n table(2 dimensionalarray havin n rows and n columns) of real values and returns average of the values on its upper left to lowerright diagonal. I would greatly appreciate your help....
Explanation / Answer
double diagonalAvg(double[][] matrix, int n){ //Matrix is the 2D array and n isthe size of it. double avg = 0; int i, j; for(i = 0; i < size; i++){ avg += matrix[i][i]; } return (double)avg/size; }