1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include struct student
{
int num;
char name[20];
float score[3], average;
};
int main(void)
{
int i, j;
struct student std[10] = {0}, temp;
puts("please enter information of student : ");
for (i = 0; i < 10; ++i)
{
scanf("%d%s", &std[i].num, std[i].name);
for (j = 0; j < 3; ++j)
{
scanf("%f", &std[i].score[j]);
std[i].average += std[i].score[j];
}
std[i].average /= 3;
}
for (i = 0; i < 9; ++i)
{
for (j = 0; j < 9 - i; ++j)
{
if (std[j].average < std[j + 1].average)
{
temp = std[j];
std[j] = std[j + 1];
std[j + 1] = temp;
}
}
}
for (i = 0; i < 10; ++i)
{
printf("num=%d name=%-6s ", std[i].num, std[i].name);
printf("score1=%0.2f score2=%0.2f score3=%0.2f ", std[i].score[0], std[i].score[1], std[i].score[2]);
printf("average=%0.2f\n", std[i].average);
}
return 0;
}