This Program Finds the saddle points in a Matrix and shows it.
Finding Saddle Point of Matrix
- #include<stdio.h>
- int row,colm,eq=1;
- int rw(int r,int dec);//determinning the max & min of the row
- int col(int r,int dec);//determinning the max & min of the coloumn
- int num[10][10];
- int main()
- {
- int i,j,sadl[50],min_r,max_r,min_c,max_c,cnt=0,dec_r[10],dec_c[10];
- printf("\nEnter How many Number of Rows in the matrix:-");
- scanf("%d",&row);
- printf("Enter How many Number of Coloumns in the matrix:-");
- scanf("%d",&colm);
- printf("\n");
- for(i=1;i<=row;i++)
- {
- for(j=1;j<=colm;j++)
- {
- printf("Enter the Element of %d row and %d coloumn:-",i,j);
- scanf("%d",&num[i][j]);
- }
- }
- printf("\nThe matrix is :-\n");
- for(i=1;i<=row;i++)
- {
- for(j=1;j<=colm;j++)
- {
- printf("%d\t",num[i][j]);
- }
- printf("\n");
- }
- for(i=1;i<=row;i++)
- {
- min_r=rw(i,0);
- max_r=rw(i,1);
- for(j=1;j<=colm;j++)
- {
- max_c=col(j,1);
- if(max_c==min_r && eq!=0)
- {
- printf("\nRow:-%d Coloumn:-%d Saddle Point Number:-%d",i,j,max_c);
- cnt++;
- }
- min_c=col(j,0);
- if(max_r==min_c && eq!=0)
- {
- printf("\nRow:-%d Coloumn:-%d Saddle Point Number:-%d",i,j,min_c);
- cnt++;
- }
- }
- }
- if(cnt==0) printf("\nThere are no saddle points.");
- printf("\n");
- return 0;
- }
- int rw(int r,int dec)
- {
- int i,min,max;
- min=num[r][1];
- max=min;
- for(i=2;i<=colm;i++)
- {
- if(min>num[r][i])
- min=num[r][i];
- if(max<num[r][i])
- max=num[r][i];
- }
- if(max==min) eq=0;
- else if(dec==0) return min;
- else return max;
- }
- int col(int r,int dec)
- {
- int i,max,min;
- max=num[1][r];
- min=max;
- for(i=2;i<=row;i++)
- {
- if(max<num[i][r])
- max=num[i][r];
- if(min>num[i][r])
- min=num[i][r];
- }
- if(max==min) eq=0;
- else if(dec==0) return min;
- else return max;
- }
Clarification is given here.
eta really helpful for me.....thanks a lot....
U r most wlcom....u can post ur sussgestion how can i improve this site...
Good..:)Here's a saddle point finder program that can handle matrices of arbitrary order..See that too..:) http://jithusunnyk.blogspot.com/2011/03/saddle-points-of-matrix.html
Good try....bt when there'll be no saddle points...then what'll be the o/p 4 ur program...Check out that...again...congo 4 the code...
what's dec?
See the clarification here: http://codes-n-tricks.blogspot.in/2010/10/saddle-point-algorithm-clarification.html
Thanks i wrote this algorithm in Free Pascal but it doesn't works, i dunno whats the problem
loop does not start at all
soon as the user enters the input for the matrix,it brings user back to the main page.
using turbo c++
can u tell the reason 4 it