課程
/后端開發(fā)
/C++
/C++遠(yuǎn)征之起航篇
return temp;的作用是什么, 為什么不加不管是輸入0或是1,輸出結(jié)果都是4
2015-10-25
源自:C++遠(yuǎn)征之起航篇 5-1
正在回答
#include<iostream>using namespace std;int get(int *a,int m,bool isMax){?int temp=a[0];?? for(int i=1;i<m;i++)?? {??? if(isMax)?? {?? if(temp<a[i])?? {?? temp=a[i];?? }?? }? else ? { if(temp>a[i])? {??temp=a[i];?}?? }?? }
}
int main(){?int a[5]={3,5,7,1,10};?? bool isMax=false;?? cin>>isMax;?? cout<<get(a,5,isMax)<<endl;?? }
續(xù)冩申話
代碼出來(lái)看看
Hc丶 提問(wèn)者
舉報(bào)
C++亮點(diǎn)盡在其中,本課程是在C語(yǔ)言基礎(chǔ)上的一個(gè)延伸,得以升華
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2015-11-01
#include<iostream>
using namespace std;
int get(int *a,int m,bool isMax)
{
?int temp=a[0];
?? for(int i=1;i<m;i++)
?? {
??? if(isMax)
?? {
?? if(temp<a[i])
?? {
?? temp=a[i];
?? }
?? }
? else
? { if(temp>a[i])
? {
??temp=a[i];
?}
?? }
?? }
}
int main()
{
?int a[5]={3,5,7,1,10};
?? bool isMax=false;
?? cin>>isMax;
?? cout<<get(a,5,isMax)<<endl;
??
}
2015-10-29
代碼出來(lái)看看