From 3b734b9f58250cf0ae6667b204ac09e0c491f2eb Mon Sep 17 00:00:00 2001 From: p62jhspgx <2736273201@qq.com> Date: Sun, 5 Nov 2023 18:41:46 +0800 Subject: [PATCH] ADD file via upload --- t3.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 t3.c diff --git a/t3.c b/t3.c new file mode 100644 index 0000000..379601a --- /dev/null +++ b/t3.c @@ -0,0 +1,96 @@ +#include +typedef struct INFO +{ + int num; + float Maths; + float Physics; + float English; + float sum; + float average; +}Info; +Info stu[3]; +void menu(); +void info(); +void grade_sort(); +int main() +{ + menu(); + info(); + grade_sort(); +} +void info() +{ + for (int i = 0; i < 3; i++) + { + scanf("%d%f%f%f", &stu[i].num, &stu[i].Maths, &stu[i].Physics, &stu[i].English); + } +} +void menu() +{ + for (int i = 0; i < 30; i++) + { + printf(" "); + } + printf("1.Input\n"); + for (int i = 0; i < 30; i++) + { + printf(" "); + } + printf("2.Output\n"); + for (int i = 0; i < 30; i++) + { + printf(" "); + } + printf("3.Order\n"); + for (int i = 0; i < 30; i++) + { + printf(" "); + } + printf("4.Quit\n"); + char c; + scanf("%c", &c); + if (c == 'i') + { + printf("Please input info of the three students:\n"); + } + else if (c == 'o') + { + printf("You are trying to Output info\n"); + } + else if (c == 'm') + { + printf("You are trying to Make things ordered\n"); + } + else if (c == 'q') + { + printf("You are about to Quit\n"); + } + else{ + printf("Wrong input\n"); + } +} +void grade_sort() +{ + for (int i = 0; i < 3; i++) + { + stu[i].sum = stu[i].Maths + stu[i].Physics + stu[i].English; + stu[i].average = stu[i].sum / 3; + } + for (int i = 0; i < 3; i++) + { + + for (int j = 2; j > i; j--) + { + if (stu[j].sum < stu[j - 1].sum) + { + Info tmp = stu[j]; + stu[j] = stu[j - 1]; + stu[j - 1] = tmp; + } + } + } + for (int i = 0; i < 3; i++) + { + printf("%d,%.1f,%.1f\n", stu[i].num, stu[i].sum, stu[i].average); + } +} \ No newline at end of file