Write a definition for a function SHOWMID (int P[][5], int R, int C) in C++ to display the elements of the middle row and middle column from a two-dimensional array P having R number of rows and C number of columns. For example, if the content of the array is as follows:
115 | 112 | 116 | 101 | 125 |
103 | 101 | 121 | 102 | 101 |
185 | 109 | 109 | 160 | 172 |
The function should display the following as output :
103 101 121 102 101
116 121 109
void SHOWMID(int P[][5],int R,int C)
{
if(R%2!=0)
{
for (int J=0;J<C;J++)
cout<<P[R/2][J]<< ' ';
}
else
cout<<'No Middle Row';
cout<<endl;
if(C%2!=0)
{
for (int I=0;I<R;I++)
cout<<P[I][C/2]<< ' ';
}
else
cout<<'No Middle Column';
}