課程
/后端開發(fā)
/C
/C語言入門
為什么這個(gè)代碼的運(yùn)行結(jié)果是降序排列:10個(gè)63,
2019-08-11
源自:C語言入門 6-12
正在回答
試試把倒數(shù)第十三行的score[j]改成score[i]
我人暈了 提問者
score[j]對(duì)應(yīng)的只有一個(gè)值
#include <stdio.h>
int sum(int score[10])
{
? ? int i;
? ? int j=0;
? ? for(i=0;i<10;i++)
? ? {
? ? ? ? j+=score[i];
? ? }
? ? return j;
}
int max(int score[10])
? ? int i,j;
? ? j=score[0];
? ? ? ? if(score[i]>j)
? ? ? ? {
? ? ? ? ? ? j=score[i];
? ? ? ? }
int min(int score[10])
? ? ? ? if(score[i]<j)
float average(int score[10])
? ? int j=0.0;
? ? return (j+0.0)/10;
void gradeDown()
? ? printf("降序排列為:");
? ? int score[10]={67,98,75,63,82,79,81,91,66,84};
? ? int i,j,k;
? ? for(i=9;i>=0;i--)
? ? ? ? for(j=0;j<i;j++)
? ? ? ? ? ? if(score[j]<score[j+1])
? ? ? ? ? ? {
? ? ? ? ? ? ? ? k=score[j+1];
? ? ? ? ? ? ? ? score[j+1]=score[j];
? ? ? ? ? ? ? ? score[j]=k;
? ? ? ? ? ? }
? ? ? ? printf("%d ",score[j]);
int main()
? ? printf("總分:%d\n",sum(score));
? ? printf("最高分:%d\n",max(score));
? ? printf("最低分:%d\n",min(score));
? ? printf("平均分:%.1f\n",average(score));
? ? gradeDown();
? ? return 0;
現(xiàn)在改成這樣又全是98了
你把代碼貼出來,我在你代碼基礎(chǔ)上改。
舉報(bào)
C語言入門視頻教程,帶你進(jìn)入編程世界的必修課-C語言
1 回答請(qǐng)問dalao們我這個(gè)應(yīng)該怎么修改
3 回答第五行代碼應(yīng)該怎么改呀?
3 回答這個(gè)代碼應(yīng)該怎么改才對(duì)?
2 回答如果我想輸出的是yes或no應(yīng)該怎么改?
1 回答應(yīng)該怎么做
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)
2019-08-18
試試把倒數(shù)第十三行的score[j]改成score[i]
2019-08-18
score[j]對(duì)應(yīng)的只有一個(gè)值
2019-08-12
#include <stdio.h>
int sum(int score[10])
{
? ? int i;
? ? int j=0;
? ? for(i=0;i<10;i++)
? ? {
? ? ? ? j+=score[i];
? ? }
? ? return j;
}
int max(int score[10])
{
? ? int i,j;
? ? j=score[0];
? ? for(i=0;i<10;i++)
? ? {
? ? ? ? if(score[i]>j)
? ? ? ? {
? ? ? ? ? ? j=score[i];
? ? ? ? }
? ? }
? ? return j;
}
int min(int score[10])
{
? ? int i,j;
? ? j=score[0];
? ? for(i=0;i<10;i++)
? ? {
? ? ? ? if(score[i]<j)
? ? ? ? {
? ? ? ? ? ? j=score[i];
? ? ? ? }
? ? }
? ? return j;
}
float average(int score[10])
{
? ? int i;
? ? int j=0.0;
? ? for(i=0;i<10;i++)
? ? {
? ? ? ? j+=score[i];
? ? }
? ? return (j+0.0)/10;
}
void gradeDown()
{
? ? printf("降序排列為:");
? ? int score[10]={67,98,75,63,82,79,81,91,66,84};
? ? int i,j,k;
? ? for(i=9;i>=0;i--)
? ? {
? ? ? ? for(j=0;j<i;j++)
? ? ? ? {
? ? ? ? ? ? if(score[j]<score[j+1])
? ? ? ? ? ? {
? ? ? ? ? ? ? ? k=score[j+1];
? ? ? ? ? ? ? ? score[j+1]=score[j];
? ? ? ? ? ? ? ? score[j]=k;
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? for(i=0;i<10;i++)
? ? {
? ? ? ? printf("%d ",score[j]);
? ? }
}
int main()
{
? ? int score[10]={67,98,75,63,82,79,81,91,66,84};
? ? printf("總分:%d\n",sum(score));
? ? printf("最高分:%d\n",max(score));
? ? printf("最低分:%d\n",min(score));
? ? printf("平均分:%.1f\n",average(score));
? ? gradeDown();
? ? return 0;
}
現(xiàn)在改成這樣又全是98了
2019-08-12
你把代碼貼出來,我在你代碼基礎(chǔ)上改。