Write a definition for a function SUMMIDCOL(int MATRIX[][10],int N,int M) in C++, which finds the sum of the middle column’s elements of the MATRIX (Assuming N represents a number of rows and M represents number of columns, which is an odd integer).
Example: if the content of array MATRIX having N as 5 and M as 3 is as follows:
1 | 2 | 1 |
2 | 1 | 4 |
3 | 4 | 5 |
4 | 5 | 3 |
5 | 3 | 2 |
The function should calculate the sum and display the following:
Sum of Middle Column: 15
void SUMMIDCOL(int MATRIX[ ][10], int N, int M)
{
int j, SUM=0;
j=M/2;
for(int i=0; i<N;i++){
SUM += MATRIX[i][j];
cout<<'SUM of Middle Column :'<<SUM;
}
}