I am stuck with a problem and i don\'t know how to put this in a for loop. I need the hotizontal average of the next matrix:
1 2 3 4 5
5 4 3 2 1
3 2 1 4 5
Do this in the language you want. Either Java, or Javascript. Pick one.
for (int i = 0; i < rows; ++i)
{
double sum = 0;
for (int j = 0; j < columns; ++j)
{
sum = sum + matrix[i][j];
}
double avg = sum / columns;
print(avg);
}
Basically, this is: for each row in the matrix, create a sum of all elements, and then divide the sum by the number of columns to find the average of the row.