#include #include #define N 3 // 学生数目 struct student { int id; // 学号 float math, physics, english, total, average; // 数学成绩,物理成绩,英语成绩,总成绩,平均成绩 }; void input(struct student stu[]) { int i; printf("Please input info of the three students:\n"); for (i = 0; i < N; i++) { scanf("%d%f%f%f", &stu[i].id, &stu[i].math, &stu[i].physics, &stu[i].english); stu[i].total = stu[i].math + stu[i].physics + stu[i].english; stu[i].average = stu[i].total / 3.0; } int j; struct student temp; for (i = 0; i < N - 1; i++) { for (j = 0; j < N - 1 - i; j++) { if (stu[j].total > stu[j + 1].total) { temp = stu[j]; stu[j] = stu[j + 1]; stu[j + 1] = temp; } } } for (i = 0; i < N; i++) { printf("%d,%.1f,%.1f\n", stu[i].id, stu[i].total, stu[i].average); } } void output(struct student stu[]) { int i; printf("Output student info:\n"); for (i = 0; i < N; i++) { printf("Student %d,%.1f,%.1f,%.1f,%.1f\n", stu[i].id, stu[i].math, stu[i].physics, stu[i].english, stu[i].total); } } void order(struct student stu[]) { int i, j; struct student temp; for (i = 0; i < N - 1; i++) { for (j = 0; j < N - 1 - i; j++) { if (stu[j].total > stu[j + 1].total) { temp = stu[j]; stu[j] = stu[j + 1]; stu[j + 1] = temp; } } } for (i = 0; i < N; i++) { printf("Student %d,%.1f,%.1f,%.1f,%.1f,%.1f\n", stu[i].id, stu[i].total, stu[i].average); } } int main() { struct student stu[N]; char choice; while (1) { printf(" 1.Input\n"); printf(" 2.Output\n"); printf(" 3.Order\n"); printf(" 4.Quit\n"); printf("Please input info of the three students:\n"); scanf("%c", &choice); switch (choice) { case 'i': input(stu); break; case 'o': output(stu); break; case 'r': order(stu); break; case 'q': printf("You are about to Quit\n"); exit(0); case 'm': printf("You are trying to Make things ordered\n"); break; default: printf("Wrong input\n"); break; } } return 0; }