//program to find saddle point of a matrix
//fensams@81092
#include<iostream.h>
#include<conio.h>
class matrix
{ int A[50][50],row,col;
public:
void get_matrix();
void saddle();
void put_matrix();
}M;
void matrix::get_matrix()
{ cout<<"ENTER THE ROW AND COLUMN SIZE\n";
cin>>row>>col;
cout<<"ENTER THE ELEMENTS\n";
for(int i=0;i<row;i++)
for(int j=0;j<col;j++)
cin>>A[i][j];
}
void matrix::put_matrix()
{ cout<<"THE ENTERED MATRIX IS\n";
for(int i=0;i<row;i++)
{ for(int j=0;j<col;j++)
cout<<A[i][j]<<"\t";
cout<<"\n";
}
}
void matrix::saddle()
{ int big[10],small[10],i,j,max,min;
for(i=0;i<row;i++)
{ small[i]=A[i][0];
for(j=0;j<col;j++)
if(A[i][j]<small[i])
small[i]=A[i][j];
}
for(j=0;j<col;j++)
{ big[j]=A[0][j];
for(i=0;i<row;i++)
if(A[i][j]>big[j])
big[j]=A[i][j];
}
min=big[0];
for(i=0;i<row;i++)
if(big[i]<min)
min=big[i];
max=small[0];
for(j=0;j<col;j++)
if(small[j]>max)
max=small[j];
if(max==min)
cout<<"THE SADDLE POINT : "<<min;
else
cout<<"NO SADDLE POINT\n";
}
void main()
{ clrscr();
M.get_matrix();
M.put_matrix();
M.saddle();
getch();
}
THX YOU VERY MUCH!!!!
ReplyDelete