代码是按老师讲的写的,但一直只输出最小值的,找不到错
#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]; } } } //cout<<boolalpha<<isMax; return temp; } int main(void) { int arr1[4] = {3,7,1,9}; bool isMax = false; cin>>isMax; cout<<getMaxOrMin(arr1, 4 ,isMax )<<endl; system("pause"); return 0; }