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

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

哪位大佬幫忙看看哪里錯(cuò)了


#include <stdio.h>

#define N 10

int totalscore(int score[])

{

? ? for(int i=0;i<10;i++)

? ? {

? ? ? ? int total=0;

? ? ? ? total=total+score[i];

? ? }

? ? return total;

}


int maxscore(int score[])

{

? ? int max=score[0];

? ? for(int i=0;i<9;i++)

? ? {

? ? ? ? if(score[i]>max)

? ? ? ? {

? ? ? ? ? ? max=score[i];

? ? ? ? }

? ? }

? ? return max;

}


int minscore(int score[])

{

? ? int min=score[0];

? ? for(int i=0;i<9;i++)

? ? {

? ? ? ? if(score[i]<min)

? ? ? ? {

? ? ? ? ? ? min=score[i];

? ? ? ? }

? ? }

? ? return min;

}


int averagescore(int score[])

{

? ? int average;

? ? average=(totalscore(score))/10;

? ? return average;

}


void orderscore(int score[],N)

{

? ? for(int i=N-1;i>=0;i--)

? ? {

? ? ? ? for(int j=0;j<=i;j++)

? ? ? ? {

? ? ? ? ? ? if(score[j]<score[j+1])

? ? ? ? ? ? {

? ? ? ? ? ? ? ? int temp=score[j];

? ? ? ? ? ? ? ? score[j]=score[j+1];

? ? ? ? ? ? ? ? score[j+1]=score[j];

? ? ? ? ? ? }

? ? ? ? }

? ? }

? ? for(int i=0;i<10;i++)

? ? {

? ? printf("成績降序排列為:",score[i]);

? ? ? ??

? ? }

}




int main()

{

? ??

? ? int score[N]={67,98,75,63,82,79,81,91,66,84};

? ? int Total=totalscore(score);

? ? int Max=maxscore(score);

? ? int Min=minscore(score);

? ? int Average=averagescore(score);

? ??

? ? printf("總分為:%d",Total);

? ? printf("最高分為:%d",Max);

? ? printf("最低分為:%d",Min);

? ? printf("平均分為:%d",Average);

? ? order(score);

? ? return 0;

}


正在回答

1 回答

主要問題在排序函數(shù)

1,首先調(diào)用的函數(shù)名order(score);和您定義的函數(shù)名void orderscore(int score[],N)就匹配不上,

2,您的冒泡排序算法寫錯(cuò)了,應(yīng)該是數(shù)組越界了,

第一層循環(huán),i取值范圍9->0,

第二層循環(huán),j取值范圍0->9,這里就出問題了,j+1的取值范圍就是1->10,當(dāng)score[10]就是越界了

3,可以把j的取值范圍限制到0->8,就沒問題了,這段修改一下

?for(int i=N-1;i>=0;i--)

? ? {

? ? ? ? for(int j=0;j<=i-1;j++)

? ? ? ? {

? ? ? ? ? ? if(score[j]<score[j+1])

? ? ? ? ? ? {

? ? ? ? ? ? ? ? int temp=score[j];

? ? ? ? ? ? ? ? score[j]=score[j+1];

? ? ? ? ? ? ? ? score[j+1]=score[j];

? ? ? ? ? ? }

? ? ? ? }

? ? }


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

crabant97

int temp=score[j]; score[j]=score[j+1]; score[j+1]=score[j]; 這里也錯(cuò)了,沒有交換成功,改為這樣: int temp=score[j]; score[j]=score[j+1]; score[j+1]=temp;
2021-08-17 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

哪位大佬幫忙看看哪里錯(cuò)了

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

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

幫助反饋 APP下載

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

公眾號

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