Hi everybody, i've got an assignment for thursday that i really cant work out, the exercise asks to find the best submatrix of a given matrix of nr rows and nc columns through a function int bestsubmatrix(int nr, int nc, double S[nr][nc], double m) that has to return the biggest submatrix of S[nr][nc] where the average of its elements doesnt have to exceed the value of m, example:

nr = 5, nc = 4, m = 2.6

matrix[nr][nc] = {

{ 5.69, 1.42,2.70,2.17},

{ 2.07, 4.01,2.78,2.88},

{ 6.84, 2.94,2.96,1.85},

{ 1.83, 1.76, 5.64, 5.51 },

{ 6.31, 5.50, 4.26, 6.10 }

};

the function has to return 6, in fact 2.70 + 2.17 + 2.78 + 2.88 + 2.96 + 1.85 / 6 = 2.55 < m

till now thats what i was able to write:

i made a void function so that i could use the printf, but i didnt get what i expected, any help would be appreciate, thanksCode:void bestsubmatrix(int nr, int nc, double S[nr][nc], double m) { int i, j, hold; double sum = 0; for(i = 0; i < nr; i++) { for(j = 1; j < nc; j++) { sum = sum + S[i][j] + S[i][j - 1]; if(sum / (j + 1) <= m) { hold = j; printf("holding the %dth element of the row = %.2f\n", hold, S[i][hold]); } else { sum = 0; } } } }