InterviewSolution
Saved Bookmarks
| 1. |
Write a function in C++ which accepts a 2D array of integers and its size as arguments and display the elements of middle row and the elements of middle column. [Assuming the 2D Array to be a square matrix with odd dimension i.e., 3 x 3, 5 x 5, 7 x 7 etc….] Example, if the array content is 3 5 47 6 92 1 8Output through the function should be:Middle Row: 7 6 9Middle Column: 5 6 1 |
|
Answer» const int S=7; // or it may be 3 or 5 int DispMRowMCol(int Arr[S][S],int S) { int mid=S/2; int i; //Extracting middle row cout<<"\n Middle Row:"; for(i=0;i<S;i++) cout<<Arr[mid][i]<<" "; //Extracting middle column cout<<"\n Middle Column:"; for(i=0;i<S;i++) cout<<Arr[i][mid]<<" "; } |
|