标签:
//杨鑫 #include <iostream> #include <cstdio> #include <stdlib.h> 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() { bool isMax = false; int arr1[4] = {3, 5, 1, 7}; cout<<"请输入想要求最大值OR最小值(1 : 0)"<<endl; cin>>isMax; cout<<getMaxOrMin(arr1, 4, isMax)<<endl; system("pause"); //头文件是stdlib.h return 0; }
图片:
标签:
原文地址:http://blog.csdn.net/u012965373/article/details/46483771