From 01515ac35174b45f867c2b7a921efc77f5830d39 Mon Sep 17 00:00:00 2001 From: pfjlev589 <1600351482@qq.com> Date: Sun, 12 Nov 2023 21:22:51 +0800 Subject: [PATCH] ADD file via upload --- step2.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 step2.c diff --git a/step2.c b/step2.c new file mode 100644 index 0000000..b072941 --- /dev/null +++ b/step2.c @@ -0,0 +1,42 @@ +#include + +typedef struct { + char id[6]; + double math; + double physics; + double english; + double total; +} Student; + +void inputStudentInfo(Student *student) { + scanf("%s", student->id); + scanf("%lf", &student->math); + scanf("%lf", &student->physics); + scanf("%lf", &student->english); + student->total = student->math + student->physics + student->english; +} + +void displayStudentInfo(Student student) { + printf("%s %.1lf %.1lf %.1lf %.1lf\n", + student.id, + student.math, student.physics, student.english, student.total); +} + +int main() { + Student students[3]; + + int i=0; + while(i<3) + { + inputStudentInfo(&students[i]); + i++; + } + + printf("\n"); + for (int i = 0; i < 3; i++) { + displayStudentInfo(students[i]); + } + + return 0; +} +