# 二维数组的鞍点问题

10 篇文章 5 订阅
8 篇文章 1 订阅

#include <stdio.h>
#include <stdlib.h>

int main(){
int a[100][100];
printf("Please input the order of the matrix:");
int n,m,count=0;
scanf("%d %d",&n,&m);
//Initialization the matrix.
printf("Please input the number of your matrix.\n");
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
scanf("%d",&a[i][j]);
}
}
for(int i=0;i<n;i++){
int max=a[i][0],tempi=i,tempj=0;
for(int j=1;j<m;j++){//Find the max number of the row and noted the cols of the max number.
if(a[i][j]>max){
max=a[i][j];
tempj=j;
}
}
int flag=1;
for(int k=0;k<n;k++){//Verify whether the number "max" is the least number in this cols
//If the number that in this row is smaller than the number "max"
//That can explain the number "max" is not a saddle point.
if(a[k][tempj]<max){
flag=0;
break;
}
}
if(flag==1){//当前的数字为鞍点
count++;
printf("\nThe saddle point of this matrix is (%d,%d):%d\n",tempi,tempj,max);
}
}
if(count==0){
printf("This matrix have no saddle point.\n");
}
return 0;
}


（1）存在鞍点的情况

Please input the order of the matrix:4 5
Please input the number of your matrix.
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20

The saddle point of this matrix is (0,4):5

（2）不存在鞍点的情况

Please input the order of the matrix:4 5
Please input the number of your matrix.
1 2 3 4 11
2 4 6 8 12
3 6 9 10 15
4 8 12 16 7
This matrix have no saddle point.

• 10
点赞
• 34
收藏
觉得还不错? 一键收藏
• 0
评论
04-08 1万+
04-07
06-11 3441
05-04 2359
10-23
04-10
02-03 480
02-05 7070
11-08 402
12-29 1574

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。