以下为我自己的代码
#include <iostream>
using namespace std;
int getMaxOrMin(int *arr,int count,bool isMax){
int tempMax = arr[0];
int tempMin = arr[0];
int i;
for(i = 0;i<count;i++){
if(tempMax<arr[i]) tempMax = arr[i];
if(tempMin>arr[i]) tempMin = arr[i];
}
if(isMax) return tempMax;
else return tempMin;
}
int main() {
int count;
cout <<"请输入数组长度:"<<endl;
cin >>count;
int arr[count];
int i;
for(i = 0;i<count;i++){
cout <<"请输入第"<<i+1<<"个数"<<endl;
cin >>arr[i];
}
cout <<"请输入指令:1.获得最大值 0.获得最小值"<<endl;
bool isFlag;
cin >>isFlag;
int temp = getMaxOrMin(arr,count,isFlag);
cout <<(isFlag?"最大值":"最小值")<<"为:"<<temp;
return 0;
}
點擊查看更多內(nèi)容
3人點贊
評論
評論
共同學習,寫下你的評論
評論加載中...
作者其他優(yōu)質(zhì)文章
正在加載中
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦