第2个回答 2018-12-22
#include<stdio.h>
struct student
{
char number[16], name[16];
float chinese, math, english;
};
struct student stu[10];
struct student avg;
int input()
{
int i;
for (i = 0; i < 10; i++) {
scanf("%s%s%f%f%f", stu[i].number, stu[i].name, &stu[i].chinese, &stu[i].math, &stu[i].english);
}
return 0;
}
int average()
{
int i;
avg.chinese = 0;
avg.math = 0;
avg.english = 0;
for (i = 0; i < 10; i++) {
avg.chinese += stu[i].chinese;
avg.math += stu[i].math;
avg.english += stu[i].english;
}
avg.chinese /= 10;
avg.math /= 10;
avg.english /= 10;
return 0;
}
int max()
{
int i, j = 0;
float x = 0, sum = 0;
for (i = 0; i < 10; i++) {
x = stu[i].chinese + stu[i].math + stu[i].english;
if (x > sum){
sum = x;
j = i;
}
}
return j;
}
int main()
{
int index;
input();
average();
index = max();
printf("All average:\n");
printf("Chinese:%f, Math:%f, English:%f\n", avg.chinese, avg.math, avg.english);
printf("The winner:\n");
printf("Number:%s, Name:%s, Chinese:%f, Math:%f, English:%f\n", stu[index].number, stu[index].name, stu[index].chinese, stu[index].math, stu[index].english);
system("PAUSE");
return 0;
}