Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

An element of a matrix is said to be \"Saddle Point\" if it is the strictly larg

ID: 3595561 • Letter: A

Question

An element of a matrix is said to be "Saddle Point" if it is the strictly largest element (max) in its row and the strictly smallest element (min) in its column. For example, the matrix shown below has 2 saddle points: (A matrix may have 0-2 saddle points) 10 12 7 3 12 3 106 2 8 18 24 17 6 10 15 21 10 8 12 [118 22 4 15] Please write a C program that ask the user to input any matrix (size of matrix, and all elements in matrix), and output any saddle point(s) in the matrix (output the value and position of the saddle points)

Explanation / Answer

#include <stdio.h>

int main()
{
int i,j;

int n,m,num;
printf("Ender dimmesion of matrix ");
scanf("%d %d", &n,&m);
printf ("%d %d", n,m);
int a[n][m];
printf(" Ender matrix element of %d * %d ", n,m);
for( i =0;i<n;i++)
for (j=0;j<m;j++){
scanf("%d", &num);
a[i][j]=num;
}
// here print matrix
  
for( i =0;i<n;i++){
for (j=0;j<m;j++){
printf("%d ", a[i][j]);
}
printf(" ");
}

int min=999;
int max=-999;
int res[n+m];
int k=0,l;
int min_check;
int max_check;
int el=0;
// here start checking seddle point
for ( i=0;i<n;i++)
{
for (j=0;j<m;j++){
min=a[i][j];
max=a[i][j];
k=0;
min_check=0;
max_check=0;
// check min
for (l=0;l<m;l++)
{
// printf("%d ", a[i][l]);
if (a[i][l]<min){
min_check=1;
  
}
if (a[i][l]> max)
{
max_check=1;
}
}
// printf(" %d",a[i][j]);
// printf("min %d max %d ", min_check, max_check);
if (min_check==1 && max_check==1){
printf("");
}
  

else if(min_check==1){
min_check=0;
for (l=0;l<n;l++){
// printf("%d ", a[l][j]);
if(a[l][j]<min){
min_check=1;
}
}
if (min_check!=1)
res[el++]=a[i][j];
}
else if(max_check==1){
max_check=0;
for (l=0;l<n;l++){
// printf("%d ", a[l][j]);
if(a[l][i]>max){
max_check=1;
}
}
if (max_check!=1)
res[el++]=a[i][j];
}

  
}
}

printf(" print seddle points are: ");
for (i=0;i<el;i++)
printf("%d ", res[i]);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote