程序哪里有问题,输出结果不正确。min 5和max10(10,5,19,3)
#include <stdlib.h>
#include <iostream>
using namespace std;
int getMaxOrMin(int *arr, int count, bool isMax)
{
int temp = arr[0];
for (int i = 1; i < count; i++)
{
if (isMax)
{
if (temp < arr[i])
{
temp = arr[i];
}
}
else
{
if (temp > arr[i])
{
temp = arr[i];
}
}
return temp;
}
}
int main(void)
{
bool isMax=false;
int arr1[4] = {10,5,19,3 };
cin >> isMax;
cout << getMaxOrMin(arr1,4, isMax)<<endl;
system("pause");
return 0;
}