求大佬幫忙看看是哪里錯了。。后兩個函數的結果有問題
#include <stdio.h>
int sum;
int getsum(int score[])
? ? {? ?int i;
? ? ? ? for(i=0;i<=9;i++)
? ? ? ? {
? ? ? ? ? ??
? ? ? ? ? ? sum += score[i];
? ? ? ? }
? ? ? ? printf("考試的總分為%d\n",sum);
? ? }
void getmax(int score[])
? ? {? ?int i;
? ? ? ? for(i=0;i<9;i++)
? ? ? ? {
? ? ? ? ? ? if(score[i]>score[i+1])
? ? ? ? ? ? {? ?int temp;
? ? ? ? ? ? ? ? temp=score[i];
? ? ? ? ? ? ? ? score[i]=score[i+1];
? ? ? ? ? ? ? ? score[i+1]=temp;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? int max=score[9];
? ? ? ? printf("最高分為%d\n",max);
? ? }
void getmin(int score[])
? ? {? ?int i;
? ? ? ? for(i=0;i<9;i++)
? ? ? ? {
? ? ? ? ? ? if(score[i]<score[i+1])
? ? ? ? ? ? {? ?int temp;
? ? ? ? ? ? ? ? temp=score[i];
? ? ? ? ? ? ? ? score[i]=score[i+1];
? ? ? ? ? ? ? ? score[i+1]=temp;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? int min=score[9];
? ? ? ? printf("最低分為%d\n",min);
? ? }
int getaverage(n)
? ? {? ?
? ? ? ? printf("平均分為%d",n/10.0);
? ? ? ? return 0;
? ? }
void rank(int score[])
? ? {? ?int i,j;
? ? ? ? for(i=8;i>=0;i--)
? ? ? ? {
? ? ? ? ? ? for(j=0;j<=i;j++)
? ? ? ? ? ? if(score[j]<score[j+1])
? ? ? ? ? ? {? ?int temp;
? ? ? ? ? ? ? ? temp=score[j];
? ? ? ? ? ? ? ? score[j]=score[j+1];
? ? ? ? ? ? ? ? score[j+1]=temp;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? for(i=0;i<=9;i++);
? ? ? ? {
? ? ? ? ? ? printf("%d",score[i]);
? ? ? ? }
? ? ? ??
? ? }
int main()
{
? ? int score[10]={67,98,75,63,82,79,81,91,66,84};
? ? getsum(score);
? ? getmax(score);
? ? getmin(score);
? ? getaverage(sum);
? ? rank(score);
? ? return 0;
}
2019-02-27
這是結果