From f0b93e29743e4481a27ea837e5aadec8919f40a7 Mon Sep 17 00:00:00 2001 From: p8sljnpht <3178612685@qq.com> Date: Sat, 16 Nov 2024 10:18:12 +0800 Subject: [PATCH] ADD file via upload --- 2.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 2.c diff --git a/2.c b/2.c new file mode 100644 index 0000000..34a9e7c --- /dev/null +++ b/2.c @@ -0,0 +1,56 @@ +#include + +struct Data +{ + int ID; + float score1; + float score2; + float score3; +} stu[1001]; +int stl = 0; + +float total(struct Data* a) { + return a->score1 + a->score2 + a->score3; +} + +void swap(struct Data* a, struct Data* b) { + struct Data t = *a; + *a = *b; + *b = t; +} + +void input1() { + scanf("%d", &stu[stl].ID); + scanf("%f", &stu[stl].score1); + scanf("%f", &stu[stl].score2); + scanf("%f", &stu[stl].score3); + stl++; +} + +void Question1() { + printf("Please input info of three students:\n"); + input1();input1();input1(); + printf("%d %2.1f %2.1f %2.1f %.1f\n", stu[stl-3].ID, stu[stl-3].score1, stu[stl-3].score2, stu[stl-3].score3, total(&stu[stl-3])); + printf("%d %2.1f %2.1f %2.1f %.1f\n", stu[stl-2].ID, stu[stl-2].score1, stu[stl-2].score2, stu[stl-2].score3, total(&stu[stl-2])); + printf("%d %2.1f %2.1f %2.1f %.1f\n", stu[stl-1].ID, stu[stl-1].score1, stu[stl-1].score2, stu[stl-1].score3, total(&stu[stl-1])); + +} + +void Typein() +{ + scanf("%d", &stu[stl].ID); + scanf("%f", &stu[stl].score1); + scanf("%f", &stu[stl].score2); + scanf("%f", &stu[stl].score3); + stl++; +} + +int main() { + Typein(); + Typein(); + Typein(); + printf("%d %2.1f %2.1f %2.1f %.1f\n", stu[stl-3].ID, stu[stl-3].score1, stu[stl-3].score2, stu[stl-3].score3, total(&stu[stl-3])); + printf("%d %2.1f %2.1f %2.1f %.1f\n", stu[stl-2].ID, stu[stl-2].score1, stu[stl-2].score2, stu[stl-2].score3, total(&stu[stl-2])); + printf("%d %2.1f %2.1f %2.1f %.1f\n", stu[stl-1].ID, stu[stl-1].score1, stu[stl-1].score2, stu[stl-1].score3, total(&stu[stl-1])); + +} \ No newline at end of file