Saddle point: The element on the position is the largest on the row, the smallest on the column. There may also be no saddle points.
1#include <stdio.h>2#include <stdlib.h>3 #defineN 44 #defineM 55 intMain ()6 {7 intI,j,k,maxj,max,a[n][m],flag;8printf"input matrix:\n");9 for(i=0; i<n;i++){Ten for(j=0; j<m;j++){ Onescanf"%d",&a[i][j]); A } - } - for(i=0; i<n;i++){ the for(j=0; j<m;j++){ -printf"%5d", A[i][j]); - } -printf"\ n"); + } - for(i=0; i<n;i++){ +max=a[i][0];//start assuming a[i][0] Max Amaxj=0;//The column number of the maximum number exists in the MAXJ at for(j=0; j<m;j++) {//Find the maximum row value - if(a[i][j]>max) { -max=A[i][j]; -Maxj=j;//The column number of the maximum number exists in the MAXJ - } - } inflag=1;//assumed to be a saddle point - for(k=0; k<n;k++){ to if(Max > A[K][MAXJ]) {//Compare the maximum number of rows to the same column element +flag=0;//If the number is not the smallest of the same column, the representation is not the saddle point, making flag=0; - Continue;//jump out of the K loop the } * } $ if(flag) {//A flag of 1 means a saddle point.Panax Notoginsengprintf"a[%d][%d]=%d\n", I,maxj,max); - Break;//jump out of I loop the } + } A if(!flag) theprintf"Not exist\n"); +System"Pause"); - return 0; $}
Finding the "saddle point" of a two-dimensional array