亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

輸出成績降序排列時有亂碼。

#include?<stdio.h>

//計算考試總分
int?total(int?score[])
{
????int?i;
????int?total?=?0;
????for(i=0;i<=9;i++)
????{
????????total?+=?score[i];
????}
????return?total;
}


//計算考試最高分數
int?highest(int?score[])
{
????int?i;
????for(i=0;i<=9;i++)
????{
????????if(score[i]>score[i+1])?//調換順序
????????{
????????????int?n?=?score[i];
????????????score[i]?=?score[i+1];
????????????score[i+1]?=?n;
????????}
????}
????return?score[9];
}

//計算考試最低分數
int?lowest(int?score[])
{
????int?i;
????for(i=0;i<=8;i++)
????{
????????if(score[i]<score[i+1])
????????{
????????????int?n?=?score[i];
????????????score[i]?=?score[i+1];
????????????score[i+1]?=?n;
????????}
????}
????return?score[0];
}

//計算考試平均分數
int?average(int?score[])
{
????int?n?=?total(score);
????int?av?=?n/10;
????return?av;
}


//考試分數降序排列
int?down_ordinary(int?score[])
{
????int?i;
????int?j;
????for(i=9;i>=1;i--)
????{
????????for(j=1;j<=i;j++)
????????{
????????????if(score[j]<score[j+1])
????????????{
????????????????int?n?=?score[j];
????????????????score[j]?=?score[j+1];
????????????????score[j+1]?=?n;
????????????}
????????}
????}
????printf("考試成績降序排列為:");
????for(i=1;i<=9;i++)
????{
????????printf("%d?",score[i]);
????}
????return?0;
}


//主函數
int?main()
{
????int?score[10]={67,98,75,63,82,79,81,91,66,84};
????printf("考試總分為%d\n",total(score));
????printf("考試最高分為%d\n",highest(score));
????printf("考試最低分為%d\n",lowest(score));
????printf("考試平均分為%d\n",average(score));
????down_ordinary(score);

????return?0;
????
????}


輸出結果

考試總分為786
考試最高分為98
考試最低分為75
考試平均分為78
考試成績降序排列為:586547409?98?91?84?82?81?79?67?66


為什么多了一個586547409出來?還有 75,63兩項不見了

正在回答

2 回答

#include <stdio.h>
//計算考試總分
int total(int score[])
{
??? int i;
??? int total = 0;
??? for(i=0;i<=9;i++)
??? {
??????? total += score[i];
??? }
??? return total;
}
?
?
//計算考試最高分數
int highest(int score[])
{
??? int i;
??? for(i=0;i<=9;i++)
??? {
??????? if(score[i]>score[i+1]) //調換順序
??????? {
?????? ??? ?int n;
??????????? n = score[i];
??????????? score[i] = score[i+1];
??????????? score[i+1] = n;
??????? }
??? }
//??? printf("%d\n",score[9]);
??? return score[9];
}
?
//計算考試最低分數
int lowest(int score[])
{
??? int i;
??? for(i=0;i<=8;i++)
??? {
??????? if(score[i]<score[i+1])
??????? {
??????????? int n = score[i];
??????????? score[i] = score[i+1];
??????????? score[i+1] = n;
??????? }
??? }
??? return score[0];
}
?
//計算考試平均分數
int average(int score[])
{
??? int n = total(score);
??? int av = n/10;
??? return av;
}
?
?
//考試分數降序排列
int down_ordinary(int score[])
{
??? int i;
??? int j;
??? for(i=9;i>=0;i--)
??? {
??????? for(j=0;j<i;j++)
??????? {
??????????? if(score[j]<score[j+1])
??????????? {
?????????? ??? ?int n;
??????????????? n = score[j];
??????????????? score[j] = score[j+1];
??????????????? score[j+1] = n;
??????????? }
??????? }
??? }
??? printf("考試分數降序排列:");
??? for(i=0;i<10;i++)
??? {
//?? ??? ?printf("%d\n",score[0]);
??????? printf("%d ",score[i]);
??? }
??? return 0;
}
?
?
//主函數
int main()
{
??? int score[10]={67,98,75,63,82,79,81,91,66,84};
??? printf("考試總分為%d\n",total(score));
??? printf("考試最高分為%d\n",highest(score));
??? printf("考試最低分為%d\n",lowest(score));
??? printf("考試平均分為%d\n",average(score));
??? down_ordinary(score);
?
??? return 0;
??? ?
??? }


給你改了下,在“考試分數降序排列”這下面的部分代碼錯誤了,你再看看。


0 回復 有任何疑惑可以回復我~

把62-68行代碼改成:

for(i=9;i>=0;i--)

????{

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

????????{

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

????????????{

? ? ? ? ? ? ? ? n?=?score[j];

就可以了。


0 回復 有任何疑惑可以回復我~
#1

Only_L

這樣該不夠的,下面還有一處錯了。
2017-03-05 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

輸出成績降序排列時有亂碼。

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號