Write a definition for a function ADDMIDROW(int MAT[][10], int R, int C) in C++, which finds sum of the middle row elements of the matrix MAT (Assuming C represents the number of Columns and R represents the number of rows, which is an odd integer).
For example, if the content of array MAT having R as 3 and C as 5 is as follows:
1 | 2 | 3 | 4 | 5 |
2 | 1 | 3 | 4 | 5 |
3 | 4 | 1 | 2 | 5 |
The function should calculate the sum and display the following:
Sum of Middle Row: 15
void ADDMIDROW(int MAT[][10],int R,int C)
{
int MIDR=0;
for (int J=0;J<C;J++)
{
MIDR+=MAT[R/2][J];
cout<<'Sum of Middle Row:'<<MIDR<<endl;
}
}