#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; } } 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 choose the operation:\n"); // 读取用户输入并消耗换行符 scanf(" %c", &choice); switch (choice) { case 'i': input(stu); output(stu); break; case 'o': output(stu); break; case 'r': printf("You are trying to Make things ordered\n"); break; case 'q': printf("You are about to Quit\n"); exit(0); default: printf("Wrong input\n"); break; } } return 0; }