C++ 求一个数组的最大值

练习:求一个数组的最大值

要求:

1.用到bool类型

2.函数用到命令空间

3.输入0 ->得到最大值

#include<stdlib.h>
#include<iostream>

using namespace std;

namespace A
{
	int get_MAX(int *arry, int count, bool isMAX)

	{
		int i;
		int temp = arry[0];//取得了第一个元素
		if (isMAX == 0)
		{
			for (i = 1; i < count; i++)
			{
				if (temp < arry[i])
				{
					temp = arry[i];
				}

			}


			return temp;

		}
	}

}
int main(void)
{

	int arry[4] = { 3,5,1,7 };
	bool isMAX = false;  //输入0,求数组最大值
	cin >> isMAX;
	int get_MAX(int *arry, int count, bool isMAX);
	cout <<A::get_MAX(arry, 4, isMAX) << endl;
	return 0;
	system("pause");

}

猜你喜欢

转载自blog.csdn.net/luoyir1997/article/details/82934131