C++二维数组找鞍点

鞍点即该位置的数在该行最大,该列最小,也可能没有鞍点
作者尚为初学者,若代码有不完善处,还望各位大佬斧正!
万分感谢!!

#include 
using namespace std;
int findmax(int a[4])
{
	int i, max;
	max = 0;
	for ( i = 1; i < 4; i++)
		if (a[max]<a[i])
			max = i;
	return max;
}
int findmin(int a[4],int num)
{
	int i, min;
	min = num;
	for (i = 0; i < 4; i++)
		if (a[min] > a[i])
			return 0;
	return 1;
}
int main()
{
	int a[4][4] = { {9,6,8,70}, {10,23,55,66}, {15,67,4,69}, {90,91,90,90} };
	int i, j, k, maxnum;
	int b[4],c[4];
	cout << "数组为:" << endl;
	for (i = 0; i < 4; i++)
	{
		for (j = 0;j < 4;j++)
			cout << a[i][j] << '\t';
		cout << endl;
	}
	cout << endl;
	for ( i = 0; i < 4; i++)
	{
		for ( j = 0; j < 4; j++)
			b[j] = a[i][j];
		maxnum=findmax(b);
		for ( k = 0; k < 4; k++)
			c[k] = a[k][maxnum];
		if (findmin(c, i))
			cout << "第" << i + 1 << "行有一个鞍点为:a[" << i << "][" << maxnum << "]=" << a[i][maxnum]<<endl;
		else
			cout << "第" << i+1 << "行不存在鞍点!"<<endl;
	}
	return 0;
}

C++二维数组找鞍点_第1张图片

你可能感兴趣的:(菜鸡,c++)