第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

程序哪里有問題,輸出結(jié)果不正確。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;


}


正在回答

4 回答

return temp;應(yīng)該放在for循環(huán)之后返回值!你的這個位置只進(jìn)行一次循環(huán)就被終止啦!for循環(huán)中的return中斷了循環(huán)!下次寫代碼時將中括號對應(yīng)起來就好看多啦!

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

幺怪 提問者

非常感謝!
2016-04-08 回復(fù) 有任何疑惑可以回復(fù)我~
#2

幺怪 提問者

寫的時候是對齊的,粘貼過來的時候沒注意就成這樣了。
2016-04-08 回復(fù) 有任何疑惑可以回復(fù)我~

return temp;應(yīng)該放在for循環(huán)之外,這個位置只進(jìn)行一次循環(huán)就被終止啦!for循環(huán)中的return中斷了循環(huán)!下次寫寫程序的時候要注意層次感,養(yǎng)成一個好的習(xí)慣,對以后的學(xué)習(xí)和編程過程是有百利而無一害的。

0 回復(fù) 有任何疑惑可以回復(fù)我~

只有一句代碼出錯,就是return temp;此句不應(yīng)該出現(xiàn)在循環(huán)內(nèi),而應(yīng)該出現(xiàn)在循環(huán)外,不知道你注意到了沒有?

修改之后程序運(yùn)行無錯誤。



1 回復(fù) 有任何疑惑可以回復(fù)我~

// Project01.cpp : 定義控制臺應(yīng)用程序的入口點(diǎn)。

//

#include <StdAfx.h>

#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;


}


1 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
C++遠(yuǎn)征之起航篇
  • 參與學(xué)習(xí)       290962    人
  • 解答問題       817    個

C++亮點(diǎn)盡在其中,本課程是在C語言基礎(chǔ)上的一個延伸,得以升華

進(jìn)入課程

程序哪里有問題,輸出結(jié)果不正確。min 5和max10(10,5,19,3)

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號