
3条回答 默认 最新
暗夜无风 2021-07-03 21:21关注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无用