To find Saddle point in a matrix

Started by aruljothi, Mar 31, 2009, 10:56 AM

Previous topic - Next topic

aruljothi

Code :
//Programm to find saddle point(s) in a matrix
//By Priyank Luthra BE Computer Engg. DCE
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[3][3],i,j,k,sp,minr,pos,flag=1;
cout<<"Enter the contents of the array ";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cin>>a[j];
}
cout<<"
The matrix representation of array is: ";
for(i=0;i<3;i++)
{
cout<<"
";
for(j=0;j<3;j++)
cout<<a[j]<<" ";
}
cout<<endl;

for(i=0;i<3;i++)
{
flag=1;
sp=a
  • ,pos=0;
       for(j=1;j<3;j++)
       {
        if(a[j]<sp)
        { sp=a[j];
          pos=j;
        }
       }
    for(k=0;k<3;k++)
    {
    if(a[k][pos]<sp)
    {
    flag=0;
    break;
    }
    }
    if(flag==1)
    cout<<"The saddle point of row "<<i+1<<" is "<<sp<<endl;

    }
    getch();
    }