代码答案哦 (借鉴)
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 10
int main()
{
int score[N] = {67,98,75,63,82,79,81,91,66,84};
float sum, max_score, min_score, avg;
int i, j, temp;
//计算考试总分
for(i = 0; i < N; i++)
{
sum += score[i];
}
printf("考试总分为:%.2f\n",sum);
printf("*********************************\n");
//计算考试平均分
avg = sum / N;
printf("考试平均分为:%.2f\n",avg);
printf("*********************************\n");
//考试成绩降序排序
for(i = N - 1; i > 0; i--)
{
for(j = 0; j <= i; j++)
{
if(score[j] < score[j+1])
{
temp = score[j];
score[j] = score[j+1];
score[j+1] = temp;
}
}
}
for(i = 0; i < N; i++)
{
printf("%d\t",score[i]);
}
printf("\n");
printf("*********************************\n");
//查询最高分
max_score = 0;
for(i = 0; i < N; i++)
{
if(score[i] > max_score)
{
max_score = score[i];
}
}
printf("最高分为:%.2f\n",max_score);
printf("*********************************\n");
//查询最低分
min_score = 100;
for(i = 0; i < N; i++)
{
if(score[i] < min_score)
{
min_score = score[i];
}
}
printf("最高分为:%.2f\n",min_score);
printf("*********************************\n");
return 0;
}
总分:786.00
平均分:78.60
降序排列:98 91 84 82 81 79 75 66 63
最高:98.00
最低:63.00(目前还不会用函数)