typedef struct student
{
int num;
char name[10];
float score[3];
}Student;
Student* max(Student s[], int n)
{
float max = -100;
int j = 0;
for (int i = 0; i < n; i++)
{
float tmp = s[i].score[0] + s[i].score[1] + s[i].score[2];
if (tmp > max)
{
max = tmp;
j = i;
}
}
return &s[j];
}
int main()
{
Student s[3] = {{1001, "aaa", {82.1, 75.6, 60.5}}, {1002, "bbb", {86.1, 75.6, 60.5}}, {1003, "ccc", {98.1, 75.6, 60.5}}};
Student* ans = max(s, 3);
printf("%d\n", ans->num);
system("pause");
return 0;
}
1
![img]