Tuesday 11 March 2014

Program In C++ To Find Maximum And Minimum In 2D Array

#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int a[20][20],m,n,i,j,max,min;
cout<<"Enter Number Of Rows In Array: ";
cin>>m;
cout<<"\nEnter Number Of Columns In Array: ";
cin>>n;
cout<<"\nEnter Array: ";
for(i=0;i<m;i++)
{ for(j=0;j<n;j++)
{ cin>>a[i][j]; }
}
min=max=a[0][0];
cout<<"\nMatrix Entered Is: \n";
for(i=0;i<m;i++)
{ for(j=0;j<n;j++)
{ cout<<a[i][j]<<"  ";
if(a[i][j]<min)
min=a[i][j];
if(a[i][j]>max)
max=a[i][j];
}
cout<<"\n"; }
cout<<"\nMinimum In The Array Is: "<<min;
cout<<"\nMaximum In The Array Is: "<<max;
getch();
}

No comments:

Post a Comment