課程
/后端開發
/C
/C語言入門
成績降序排序,不應該是個數組嗎,也就是說要定義一個返回值為數組的函數,怎么定義數組作為返回值?
2016-05-29
源自:C語言入門 6-12
正在回答
#include <stdio.h>
int main()
{
? ? int score[10]={67,98,75,63,82,79,81,91,66,84};
? ? int sum=0;
? ? int i;
? ? int j;
? ? for(i=0;i<10;i++)
? ? {
? ? ? ? sum+=score[i];
? ? }
? ? printf("總分%d\n",sum);
? ? printf("平均分%d\n",sum/10);
? ? for(i=0;i<9;i++)
? ? ? ? if(i<9)
? ? ? ? {
? ? ? ? ? ? for(j=0;j<9;j++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if(score[j]<score[j+1])
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? int x;
? ? ? ? ? ? ? ? ? ? x=score[j];
? ? ? ? ? ? ? ? ? ? score[j]=score[j+1];
? ? ? ? ? ? ? ? ? ? score[j+1]=x;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? printf("最高分%d\n",score[0]);
? ? printf("最低分%d\n",score[9]);
? ? printf("考試成績降序排序\n");
? ? for(j=0;j<10;j++)
? ? ? ? printf("%d\n",score[j]);
? ? return 0;
}
kming 提問者
弄好了,先定義一個void型的函數實現把數組排序,然后用for循環打印結果,網上查的不能把數組作為函數返回值,水平有限,目前只能想到這個辦法了
舉報
C語言入門視頻教程,帶你進入編程世界的必修課-C語言
2 回答輸出成績降序排列時有亂碼。
1 回答冒泡排序排序
1 回答在一個長度為10的整型數組里面,保存了班級10個學生的考試成績。要求編寫5個函數,分別實現計算考試的總分,最高分,最低分,平均分和考試成績降序排序。
3 回答數組的冒泡排序
1 回答為什么排序變成這樣?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2016-06-19
#include <stdio.h>
int main()
{
? ? int score[10]={67,98,75,63,82,79,81,91,66,84};
? ? int sum=0;
? ? int i;
? ? int j;
? ? for(i=0;i<10;i++)
? ? {
? ? ? ? sum+=score[i];
? ? }
? ? printf("總分%d\n",sum);
? ? printf("平均分%d\n",sum/10);
? ? for(i=0;i<9;i++)
? ? {
? ? ? ? if(i<9)
? ? ? ? {
? ? ? ? ? ? for(j=0;j<9;j++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if(score[j]<score[j+1])
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? int x;
? ? ? ? ? ? ? ? ? ? x=score[j];
? ? ? ? ? ? ? ? ? ? score[j]=score[j+1];
? ? ? ? ? ? ? ? ? ? score[j+1]=x;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? printf("最高分%d\n",score[0]);
? ? printf("最低分%d\n",score[9]);
? ? printf("考試成績降序排序\n");
? ? for(j=0;j<10;j++)
? ? {
? ? ? ? printf("%d\n",score[j]);
? ? }
? ? return 0;
}
2016-05-29
弄好了,先定義一個void型的函數實現把數組排序,然后用for循環打印結果,網上查的不能把數組作為函數返回值,水平有限,目前只能想到這個辦法了