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

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

為什么這個編譯能通過,但是輸出之后又重復(fù)的?

#include <stdio.h>//函數(shù)內(nèi)定義的東西只能作用于這個函數(shù)?

//計算總分和平均分?

int getSumScore(int score[])

{

? ? int i;

? ? int average;//平均分?

? ? int sum=0;

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

? ? {

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

? ? }

? ? printf("總分為%d\n",sum);

? ? average=sum/10;

? ? printf("平均分為%d\n",average);

? ? return average;

}

//計算最高分

int maxScore(int score[])

{

? ? int max=-1;

? ? int j;

? ? for(j=0;j<10;j++)

? ? {

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

? ? ? ? {

? ? ? ? ? ? max=score[j];

? ? ? ? ? ? printf("最高分為%d\n",max);

? ? ? ? }

? ? }

? ? return max;

}

//計算最低分

int minScore(int score[])

{

? ? int min=100;

? ? int k;

? ? for(k=0;k<10;k++)

? ? {

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

? ? ? ? {

? ? ? ? ? ? min=score[k];

? ? ? ? ? ? printf("最低分為%d\n",min);

? ? ? ? }

? ? }

? ? return min;

}

//考試成績降序排序

void sort(int score[])

{

? ? int x,y,z;

? ? for(x=8; x>=0; x--)//一共10個數(shù),需要比較9次,0~8是9個數(shù)

? ? {

? ? ? ? for(y=0;y<=x;y++)

? ? ? ? {

? ? ? ? ? ? if(score[y]<score[y+1] ) ? ? //當(dāng)前面的數(shù)比后面的數(shù)大時

? ? ? ? ? ? {

? ? ? ? ? ? ? ? int temp; ? ? ? ? ?//定義臨時變量temp

? ? ? ? ? ? ? ? temp=score[y]; ? ? ?//將前面的數(shù)賦值給temp

? ? ? ? ? ? ? ? score[y]=score[y+1]; //前后之?dāng)?shù)顛倒位置

? ? ? ? ? ? ? ? score[y+1]=temp; ?//將較大的數(shù)放在后面 ? ?

? ? ? ? ? ? } ? ? ? ? ? ? ? ??

? ? ? ? }

? ? }

? ? printf("---成績排名---\n");

? ? for(z=0;z<10;z++)

? ? {

? ? printf(" %d ",score[z]);

? ? }

??

}


int main()

{

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

? ? getSumScore(score);

? ? maxScore(score);

? ? minScore(score);

? ? sort(score);

? ? return 0;

}


正在回答

1 回答


http://img1.sycdn.imooc.com//589f045900016bf604740580.jpghttp://img1.sycdn.imooc.com//589f046b0001ac9404310426.jpg

輸出兩個應(yīng)該是因為 printf 語句在 if 里面。

你先是假定 max=-1,每當(dāng)判定 score[j] 大于 max 成功時就會輸出一次,所以會輸出兩次。慕課網(wǎng)頁評定系統(tǒng)又不是很完善,所以輸出兩個也能通過。

Hope that Help ! ! !

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

qq_沐鉬_04007561 提問者

非常感謝!
2017-02-12 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

為什么這個編譯能通過,但是輸出之后又重復(fù)的?

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

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

幫助反饋 APP下載

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

公眾號

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