From a0ee7dd84fa3e6a2cc6445b2ee37a7e715cf1ce3 Mon Sep 17 00:00:00 2001 From: pfwail38f <1044591285@qq.com> Date: Sun, 12 Nov 2023 22:51:12 +0800 Subject: [PATCH] ADD file via upload --- 2.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 2.c diff --git a/2.c b/2.c new file mode 100644 index 0000000..84a0fb8 --- /dev/null +++ b/2.c @@ -0,0 +1,47 @@ +#include + +// 定义学生结构体 +struct Student { + int id; + float mathScore; + float physicsScore; + float englishScore; + float totalScore; +}; + +// 函数声明 +void inputStudentInfo(struct Student* student); +void displayStudentInfo(struct Student* student); + +int main() { + // 定义三个学生 + struct Student student1, student2, student3; + + // 输入学生信息 + inputStudentInfo(&student1); + inputStudentInfo(&student2); + inputStudentInfo(&student3); + + // 显示学生信息 + displayStudentInfo(&student1); + displayStudentInfo(&student2); + displayStudentInfo(&student3); + + return 0; +} + +// 输入学生信息的函数 +void inputStudentInfo(struct Student* student) { + scanf("%d", &student->id); + scanf("%f", &student->mathScore); + scanf("%f", &student->physicsScore); + scanf("%f", &student->englishScore); + + // 计算总成绩 + student->totalScore = student->mathScore + student->physicsScore + student->englishScore; +} + +// 显示学生信息的函数 +void displayStudentInfo(struct Student* student) { + printf("%d %.1f %.1f %.1f %.1f\n", student->id, student->mathScore, student->physicsScore, student->englishScore, student->totalScore); +} \ No newline at end of file