課程
/后端開發
/C
/C語言入門
為什么這個代碼的運行結果是降序排列:10個63,
2019-08-11
源自:C語言入門 6-12
正在回答
試試把倒數第十三行的score[j]改成score[i]
我人暈了 提問者
score[j]對應的只有一個值
#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;
現在改成這樣又全是98了
你把代碼貼出來,我在你代碼基礎上改。
舉報
C語言入門視頻教程,帶你進入編程世界的必修課-C語言
1 回答請問dalao們我這個應該怎么修改
3 回答這個代碼應該怎么改才對?
3 回答第五行代碼應該怎么改呀?
2 回答如果我想輸出的是yes或no應該怎么改?
1 回答應該怎么做
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2019-08-18
試試把倒數第十三行的score[j]改成score[i]
2019-08-18
score[j]對應的只有一個值
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;
}
現在改成這樣又全是98了
2019-08-12
你把代碼貼出來,我在你代碼基礎上改。