Sunday, 28 August 2011

Saddle Point

Saddle Point of a matrix is the element which is smallest in the row and the highest in the corresponding column. A matrix may have One or Two saddle points or may not have a saddle point.


Coding:


#include<stdio.h>
#include<conio.h>

void main()
{
int a[3][3],i,j,k,b,pos,sp;
clrscr();
printf("enter the elements of matrix of order 3");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\nmatrix is\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d",a[i][j]);
printf(" ");
}
printf("\n");
}
for(i=0;i<3;i++)
{
b=1;
sp=a[i][0];
pos=0;
for(j=0;j<3;j++)
{
if(a[i][j]<sp)
{
sp=a[i][j];
pos=j;
}
}
for(k=0;k<3;k++)
{
if(a[k][pos]>sp)
{
b=0;
break;
}
}
if(b==1)
printf("saddle point is %d at position a[%d][%d]",sp,i+1,pos+1);}
if(b==0)
printf("no saddle point");
getch();
}


Output:







No comments:

Post a Comment