Saturday, August 20, 2011

Find saddle point in each row of two dimentional array.

//Find saddle point in each row of two dimentional array.
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
void create(int ***t,int r,int c);
void display(int **t,int r,int c);
void saddle(int **t,int r,int c);
main()
{
 int **a,m,n;
 printf("\n Enter the number of rows in 1st  matrix:");
 scanf("%d",&m);
 printf("\n Enter the number of columns in  1st matrix:");
 scanf("%d",&n);
 create(&a,m,n);
  saddle(a,m,n);
  printf("\n1st matrix is \n");
  display(a,m,n);
 getch();
}
void create(int ***te,int r,int c)
{
     int **t,i,j;
     t=(int**)malloc(r*sizeof(int*));
     for(i=0;i<r;i++)
     t[i]=(int*)malloc(c*sizeof(int));
     printf("Enter the elements of matrix");


     for(i=0;i<r;i++)
       for(j=0;j<c;j++)
         scanf("%d",&t[i][j]);
       
     *te=t;
}
void display(int **t,int r,int c)
{
     int i,j;
     for(i=0;i<r;i++)
     {
      for(j=0;j<c;j++)
        printf(" %d ",t[i][j]);
      printf("\n");
     }  
}
void saddle(int **t,int r,int c)
{
     int i,j,k,l,min,max;
     for(i=0;i<r;i++)
     {
         j=0;
         min=t[i][j];
         for(k=1;k<c;k++)
         {
           if(min>t[i][k])
           {
             min=t[i][k];
             j=k;
           }
         }
         l=0;
         max=t[l][j];
         for(k=1;k<r;k++)
         {
            if(max<t[k][j])
            {
               max=t[k][j];
               l=k;
            }
         }
         if(max==min)
          printf("\nsaddle point of %dth row is exits and at location %d%d",i+1,i,j);
         else
          printf("\n%d row has no saddle point",i+1);
     }
}

Previous Next Home
0 Comments
Comments

Leave a Comment

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Twitter Delicious Facebook Favorites More