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
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
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.
use c not c++. use a function named saddle to do the process. pls help. Today is the last day to submit the work.
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.
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.
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.
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
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.
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.
can u help ?
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.
i am having head ache with it. I am very low in logic. i need help.
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.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.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 ];
Quzah.
Hope is the first step on the road to disappointment.
steps to do ...
Code comes from here.
Loser. Do your own friggin homework.