Pages

Related Posts with Thumbnails
Saddle Point of Matrix – C Programming and Algorithm >> Codes-N-Tricks
Content feed Comments Feed

Saddle Point of Matrix – C Programming and Algorithm

Posted by Musically Technical Sunday, August 29, 2010

This Program Finds the saddle points in a Matrix and shows it.


Finding Saddle Point of Matrix
  1. #include<stdio.h>
  2.  
  3. int row,colm,eq=1;
  4. int rw(int r,int dec);//determinning the max & min of the row
  5. int col(int r,int dec);//determinning the max & min of the coloumn
  6.  
  7. int num[10][10];
  8.  
  9. int main()
  10. {
  11. int i,j,sadl[50],min_r,max_r,min_c,max_c,cnt=0,dec_r[10],dec_c[10];
  12.  
  13. printf("\nEnter How many Number of Rows in the matrix:-");
  14. scanf("%d",&row);
  15. printf("Enter How many Number of Coloumns in the matrix:-");
  16. scanf("%d",&colm);
  17. printf("\n");
  18. for(i=1;i<=row;i++)
  19. {
  20.      for(j=1;j<=colm;j++)
  21.      {
  22.          printf("Enter the Element of %d row and %d coloumn:-",i,j);
  23.          scanf("%d",&num[i][j]);    
  24.      }
  25. }
  26. printf("\nThe matrix is :-\n");
  27. for(i=1;i<=row;i++)
  28. {
  29.      for(j=1;j<=colm;j++)
  30.      {
  31.         
  32.          printf("%d\t",num[i][j]);
  33.      }
  34.      printf("\n");
  35. }
  36. for(i=1;i<=row;i++)     
  37. {
  38.        min_r=rw(i,0);
  39.      max_r=rw(i,1);
  40.      for(j=1;j<=colm;j++)
  41.      {
  42.          max_c=col(j,1);
  43.           if(max_c==min_r && eq!=0)
  44.          {
  45.           printf("\nRow:-%d Coloumn:-%d Saddle Point Number:-%d",i,j,max_c);
  46.           cnt++;
  47.          }
  48.          min_c=col(j,0);
  49.          if(max_r==min_c && eq!=0)
  50.          {
  51.           printf("\nRow:-%d Coloumn:-%d Saddle Point Number:-%d",i,j,min_c);
  52.           cnt++;
  53.          }
  54.      }     
  55. }         
  56. if(cnt==0) printf("\nThere are no saddle points.");
  57. printf("\n");     
  58. return 0;
  59. }
  60.  
  61. int rw(int r,int dec)
  62. {
  63. int i,min,max;
  64. min=num[r][1];
  65. max=min;
  66. for(i=2;i<=colm;i++)
  67. {
  68.   if(min>num[r][i])
  69.    min=num[r][i];
  70.   if(max<num[r][i])
  71.    max=num[r][i];
  72. }
  73. if(max==min) eq=0;
  74. else if(dec==0) return min;
  75.       else return max;
  76. }  
  77.  
  78. int col(int r,int dec)
  79. {
  80. int i,max,min;
  81. max=num[1][r];
  82. min=max;
  83. for(i=2;i<=row;i++)
  84. {
  85.   if(max<num[i][r])
  86.    max=num[i][r];
  87.   if(min>num[i][r])
  88.    min=num[i][r];
  89. }
  90. if(max==min) eq=0;
  91. else if(dec==0) return min;
  92.       else return max;
  93. }

Clarification is given here.

8 Responses to Saddle Point of Matrix – C Programming and Algorithm

  1. eta really helpful for me.....thanks a lot....

     
  2. U r most wlcom....u can post ur sussgestion how can i improve this site...

     
  3. Anonymous Says:
  4. 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

     
  5. 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...

     
  6. akatar Says:
  7. what's dec?

     
  8. See the clarification here: http://codes-n-tricks.blogspot.in/2010/10/saddle-point-algorithm-clarification.html

     
  9. akatar Says:
  10. Thanks i wrote this algorithm in Free Pascal but it doesn't works, i dunno whats the problem

     
  11. sg Says:
  12. 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

     

Post a Comment

SyntaxHighlighter

E-Mail Subscription

Enter your email address:

Subscribe & get Regular E-Mail Updates From Codes-N-Tricks.
Delivered by FeedBurner

There was an error in this gadget

Share with Orkut

Loading

Google Translation

Recent Posts

About Us

Musically Technical
View my complete profile