希望大佬帮我看看这个排序部分的代码,我要崩溃了
#include <stdio.h>
int getsum(int score[10])
{
int sum = 0;
int i;
for (i = 0; i < 10; i++)
{
sum = sum + score[i];
if (i == 9)
{
printf("总分为 % d\n", sum);
}
}
return 0;
}
int getmax(int score[10])
{
int max,i;
int index;
max = score[0];
index = 0;
for (i = 0; i <10; i++)
{
if (score[i] > max)
{
max = score[i];
index == i;
printf("最高分为%d\n", max);
}
}
return 0;
}
int getmin(int score[10])
{
int j;
int min;
min = score[0];
for (j = 0; j < 10; j++)
{
if (score[j] < min)
{
min = score[j];
printf("最低分为%d\n", min);
}
}
return 0;
}
float average(int score[10])
{
float sum = 0;
float aver;
int k;
for (k = 0; k < 10; k++)
{
sum = sum + score[k];
if (k == 9)
{
aver = sum / 10;
printf("平均分为%f\n", aver);
}
}
return 0;
}
int down(int score[10])
{
int n, t;
for (n = 1; n < 10; n++)
{
for (t = 0; t <9-n; t++)
{
if (score[t+1] > score[t])
{
int temp;
temp = score[t+1];
score[t+1] = score[t];
score[t] = temp;
}
}
}
printf("考试成绩降序如下: \n");
for (n = 0; n < 10; n++)
{
printf("%d ", score[n]);
}
return 0;
}
int main()
{
int score[10] = { 67,98,75,63,82,79,81,91,66,84 };
getsum(score);
getmax(score);
getmin(score);
average(score);
down(score);
return 0;
}
排序结果前8个都正常,最后一个数却是84,试了几次都不知道毛病出在哪里