Wednesday, February 11, 2015

C Program to find highest and lowest element of a Matrix

C++ Program to find highest and lowest element of a Matrix


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

void main()
{
 clrscr();
 int m,n,a[10][10],i,j,high,low;
 cout<<"Enter no. of rows and coloumns:";
 cin>>m>>n;
 cout<<"
Enter matrix:
";

 for(i=0;i<m;++i)
 {
  for(j=0;j<n;++j)
   cin>>a[i][j];
 }


 for(i=0;i<m;++i)
 {
 high=a[0][0];
  low=a[0][0];
  for(j=0;j<n;++j)
  {
   if(a[i][j]>high)
    high=a[i][j];
   else
    if(a[i][j]<low)
     low=a[i][j];
  }
 }
  cout<<"
Heighst Element:"<<high<<"
Lowest Element:"<<low<<"
";

 getch();
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.