#include<iostream>
using namespace std;
//找出一个二维数组中的鞍点(该元素在该行最大,该列最小)
int main()
{
int a[100][100], m, n;
int i, j, k;
bool flag;
cout << "输入矩阵的行数,列数:";
cin >> m >> n;
cout << "输入矩阵:" << endl;
for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
cin >> a[i][j];
for (i = 0; i < m; i++)
{
int max = a[i][0], maxj;
for (j = 0; j < n; j++)
if (a[i][j] > max)
{
max = a[i][j]; //首先求出一行最大的数
maxj = j; //并记录行号
}
flag = true;
for (k = 0; k < m; k++)
if (max > a[k][j]) //如果在最大数这一列其他数都比他小,则是鞍点
{
flag = true;
continue;
}
if (flag)
{
cout << endl;
cout << "a[" << i << "][" << maxj << "]=" << max << "是鞍点。" << endl;
break;
}
}
if (!flag)
cout << "鞍点不存在!" << endl;
return 0;
}
来源:CSDN
作者:阿晶呐
链接:https://blog.csdn.net/weixin_44817229/article/details/104822119