Make Your Search Easy ! :) Use me

Sunday, February 26, 2017

Q. Write a function definition for a function void show_mid(int p[ ][ ], int r, int c) in C++ to display the elements of middle row and middle column from a two dimensional array p having number of columns r and number of rows c.

#include<conio.h>
#include<iostream.h>

/* FUNCTION DEFINITION TO SHOW ELEMENT OF MIDDLE ROW AND COLUMN */

void show_mid(int p['z']['z'],int r, int c)
{
int midi,midc;
      if(r%2==0||c%2==0)
      {
          cout<<"\nGiven array has no Middle Row/Column";
            return;
         }
midi = (r+1)/2;
midc = (c+1)/2;
cout<<"\nElements of Middle Row are :\n";
do
{
for(int j=0;j<c;j++)
{
cout<<p[midi][j]<<"\t";
}

}while(0);
cout<<"\nElements of Middle Column are :\n";
do
{
for(int j=0;j<r;j++)
{
cout<<p[j][midc]<<"\t";
}

}while(0);
}

/* MAIN FUNCTION */

void main()
{
int a['z']['z'],r,c;
cout<<"\nEnter No. of Rows : ";
cin>>r;
cout<<"\nEnter No. of Columns : ";
cin>>c;
cout<<"\nEnter an Array : \n";
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cin>>a[i][j];
}
}
show_mid(a,r,c);
getch();

}

No comments:

Post a Comment