找出一个二维数组中的鞍点,即该位置上的元素在该行上的最大、在该列上最小。也有可能没有鞍点。
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{int a[10][10] = { 0 };int n = 0, m = 0;int i = 0, j = 0;printf("请输入这个数组有n行m列:");scanf("%d %d",&n,&m);printf("请输入这个数组:\n");for (i = 0; i < n; i++){for (j = 0; j < m; j++){scanf("%d",&a[i][j]);}}//比较每一行的最大值int max[10] = { 0 };for (i = 0; i < n; i++){ max[i] = a[i][j];for (j = 0; j < m; j++){if (a[i][j] > max[i])max[i] = a[i][j];}}int min[10] = { 0 };for (i = 0; i < m; i++){min[i] = a[0][i];for (j = 0; j < n; j++){if (a[j][i] < min[i])min[i] = a[j][i];}}int flag = 0;int c = 0, b = 0,d=0;for (i = 0; i < n; i++){for (j = 0; j < m; j++){if (max[i] == min[j]){flag = 1;c = i;b = j;d = max[i];}}}if (flag == 1){printf("(%d,%d) %d\n", c, b,d);}elseprintf("没有按点\n");return 0;
}
输出结果: