//************************************************
//第10题
//35名学生,每名学生4门课程,随机产生,计算平均成绩,按平均成绩排名排名
//************************************************
#include
#include
#include
#define NUM 10
void main()
{
int stuScore[NUM][4];
double averageScore[NUM];
int sum;
srand((unsigned)time(NULL));
//随机产生35名学生,每人的四门成绩,并算出平均成绩
for(int i=0;i
{
sum=0;
for(int j=0;j<4;j++)
{
stuScore[i][j]=rand()%100+1;
sum += stuScore[i][j];
}
averageScore[i]=sum/4.0;
}
//打印出单科成绩和平均成绩
printf("单科成绩(4门) 平均成绩\n");
for(int a=0;a
{
for(int b=0;b<4;b++)
{
printf("%-3d",stuScore[a][b]);
}
printf("%8.1f",averageScore[a]);
printf("\n");
}
//采用选择排序对学生平均成绩进行排名
double temp;
int maxValue;
for(int j=0;j
{
maxValue=j;
for(int k=j+1;k
{
if(averageScore[k]>averageScore[maxValue])
{
maxValue=k;
}
}
if(maxValue != j)
{
temp = averageScore[j];
averageScore[j] = averageScore[maxValue];
averageScore[maxValue]=temp;
}
}
//打印出成绩,平均成绩,以及排名
printf("名次:\n");
for(int w=0;w
{
printf("第%d名的平均分为:%5.2f\n",w+1,averageScore[w]);
}
} 单科成绩(4门) 平均成绩 3 52 84 1 35.0 17 41 50 90 49.5 42 40 1002 46.0 94 52 36 74 64.0 56 68 45 7 44.0 71 10 73 76 57.5 65 83 10047 73.8 13 1 28 32 18.5 61 27 80 71 59.8 85 7 96 81 67.3 名次: 第1名的平均分为:73.75 第2名的平均分为:67.25 第3名的平均分为:64.00 第4名的平均分为:59.75 第5名的平均分为:57.50 第6名的平均分为:49.50 第7名的平均分为:46.00 第8名的平均分为:44.00 第9名的平均分为:35.00 第10名的平均分为:18.50 请按任意键继续. . .