#include "stdafx.h"
#include<stdlib.h>
#include<iostream>
using namespace std;
namespace Com {
int maxOrmin(int *arr, int length, bool isMax) {
int temp = arr[0];
for (int i = 1; i < length; i++) {
if (isMax) {
if (temp < arr[i]) {
temp = arr[i];
}
}
else {
if (temp > arr[i]) {
temp = arr[i];
}
}
}
return temp;
}
}
int main()
{
int arr[4] = { 7,5,6,9 };
bool isMax;
cin >> isMax;
cout << Com::maxOrmin(arr, 4, isMax) << endl;
system("pause");
return 0;
}
本文介绍了一个使用C++编写的简单程序,该程序通过一个函数实现对整型数组的最大值或最小值的查找。根据用户输入的标志位决定是寻找最大值还是最小值。
1213

被折叠的 条评论
为什么被折叠?



