#include <stdio.h>
//分数总数
int total(int score[])
{
int j;
int sum = 0;
for (j=0;j<10;j++)
{
sum += score[j];
}
return sum;
}
//最高分
int max(int score[])
{
int j;
int sum = 0;
for (j = 0; j < 10; j++)
{
if(score[j]>score[j+1])
{
sum = score[j];
score[j] = score[j + 1];
score[j + 1] = sum;
}
}
return sum;
}
//最低分
int min(int score[])
{
int j;
int sum = 0;
for (j = 0; j < 10; j++)
{
if (score[j] > score[j + 1])
{
sum = score[j];
score[j] = score[j + 1];
score[j + 1] = sum;
}
}
return score[0];
}
//平均分
int average(int score[])
{
int j;
int sum = 0;
for (j = 0; j < 10; j++)
{
sum += score[j];
}
sum /= 10;
return sum;
}
int main()
{
int score[10] = { 67,98,75,63,82,79,81,91,66,84 };
int totalsum=total(score);
printf("总分是%d\n", totalsum);
int maxsum = max(score);
printf("最高分是%d\n", maxsum);
int minsum = min(score);
printf("最低分是%d\n", minsum);
int averagesum = average(score);
printf("平均分是%d\n", averagesum);
return 0;
}
跑了一下没有发现溢出啊。