Thread: program to find the saddle point of a matrix ??

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    14

    Angry program to find the saddle point of a matrix ??

    Write a program to find the saddle point of a matrix ( a[i][j] is the smallest value in th ith row and the largest alue in the jth column

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    So write it.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    14

    pls write this program for me

    use c not c++. use a function named saddle to do the process. pls help. Today is the last day to submit the work.

  4. #4
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Nobody here is going to do your homework for you. If you put in some effort and show your code, people will guide you along and provide hints to fix it and make it work.

    Please read the Homework policy for this site.

    Even if today is the last day to submit it if you start working on it now, it will probably only take you about 1-2 hours to get it done, and that includes the time it takes to post your intermediate code here.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    14

    i have done it. but need u r help

    i will post the code here

    Code:
    saddlepointa(int a1[10][10],int rowa,int cola)
    {
     int big[10],small[10],i,j,max,min;
     clrscr();
     big[0]=a1[0][0];
     for(i=0;i<rowa;i++)
     {
      for(j=0;j<cola;j++)
      {
       if(a1[i][j] > big[i])
       {
         big[i] = a1[i][j];
       }
      }
     }
     for(j=0;j<cola;j++)
     {
      small[j]=a1[0][j];
      for(i=0;i<rowa;i++)
      {
       if(a1[i][j] < small[j])
       {
        small[j]=a1[i][j];
       }
      }
     }
     min=big[0];
     for(i=0;i<rowa;i++)
     {
      if(big[i] < min)
      {
       min = big[i];
      }
     }
     max=small[0];
     for(j=0;j<cola;j++)
     {
      if(small[j] > max)
      {
       max = small[j];
      }
     }
     if(max==min)
     {
      printf("\n\n\n\t\t\tTHE SADDLE POINT IS --> %d ",min);
     }
     else
     {
      printf("\n\n\n\nNO SADDLE POINT");
     }
    getch();
    return 0;
    }
    void main()
    {
     int a[10][10],i,j;
     printf("Enter the matrix elements\n");
     for(i=0;i<3;i++)
     {
      for(j=0;j<3;j++)
      {
        scanf("%d",&a[i][j]);
      }
     }
    saddlepointa(a,3,3);
    getch();
    }
    Last edited by intermediatech; 05-05-2010 at 02:26 PM.

  6. #6
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Post the code using CODE TAGS! Nobody will read that.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    14

    Post ok ?

    is the post ok ?

    if we enter

    1 2 3
    4 5 6
    7 8 9

    The program will return 3 as saddle point.
    but according to question the answer is 7

    pls help to correct this

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Post is OK, (much better!).

    Let's see...

    I don't understand your logic, but here's one way:

    sort the array, in descending order.

    The value in the last row, zero column, will always be the saddlepoint.
    Last edited by Adak; 05-05-2010 at 02:45 PM.

  9. #9
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Quote Originally Posted by intermediatech View Post
    is the post ok ?

    if we enter

    1 2 3
    4 5 6
    7 8 9

    The program will return 3 as saddle point.
    but according to question the answer is 7

    pls help to correct this
    The correct answer is 7, because 7 is the smallest on its row (row 3) and largest on its col(col 1).
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  10. #10
    Registered User
    Join Date
    May 2010
    Posts
    14

    help ?

    can u help ?

  11. #11
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Your saddlepoint function finds largest in the row and smallest in the column. If you want it the other way around, then you should go the other way with your tests.

  12. #12
    Registered User
    Join Date
    May 2010
    Posts
    14

    can u do it ?

    i am having head ache with it. I am very low in logic. i need help.

  13. #13
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I'm not sure why you have so many loops. Loop once through the provided column. Store the biggest, or smallest or whatever it is you're looking for, the index of that value. Do the same thing for the row. Return the value that is at the coordinates those two indexes make.
    Code:
    for each element in this column
        if here < or > (whatever) than previous low or high
            update stored column index
    
    for each element in this row
        if here < or > (whatever) than previous low or high
            update stored row index
    
    return array[ stored row index ][ stored column index ];
    You have twice as many loops as you need, unless I'm misunderstanding what you're really trying to do. Also, your code doesn't actually spit out 3, because your code doesn't actually ever call your saddle function.


    Quzah.
    Hope is the first step on the road to disappointment.

  14. #14
    Registered User
    Join Date
    May 2010
    Posts
    14

    Tell me the steps to do ?

    steps to do ...

  15. #15
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Code comes from here.

    Loser. Do your own friggin homework.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. C program 2D matrix multiplication using malloc
    By college_kid in forum C Programming
    Replies: 5
    Last Post: 04-03-2009, 10:04 AM
  3. Matrix c program help!!!
    By kclew in forum C Programming
    Replies: 21
    Last Post: 02-25-2009, 04:46 AM
  4. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  5. Program Entry Point
    By Sentral in forum C++ Programming
    Replies: 16
    Last Post: 07-28-2006, 03:36 AM