用c语言,使用结构体输入一名学生的信息(名字,学号,班级,性别,语文,数学,英语,物理,化学,生物六门课成绩)计算平均成绩并与学生信息一起输出
时间: 2024-01-04 15:03:49 浏览: 89
好的,我可以帮你完成这个任务。以下是我给你的代码,你可以直接使用:
```c
#include <stdio.h>
//定义结构体类型
struct student_info {
char name[20];
int student_id;
char class[10];
char gender[5];
float chinese;
float math;
float english;
float physics;
float chemistry;
float biology;
};
int main() {
struct student_info student;
//输入学生信息
printf("请输入学生姓名:");
scanf("%s", student.name);
printf("请输入学生学号:");
scanf("%d", &student.student_id);
printf("请输入学生班级:");
scanf("%s", student.class);
printf("请输入学生性别:");
scanf("%s", student.gender);
printf("请输入学生语文成绩:");
scanf("%f", &student.chinese);
printf("请输入学生数学成绩:");
scanf("%f", &student.math);
printf("请输入学生英语成绩:");
scanf("%f", &student.english);
printf("请输入学生物理成绩:");
scanf("%f", &student.physics);
printf("请输入学生化学成绩:");
scanf("%f", &student.chemistry);
printf("请输入学生生物成绩:");
scanf("%f", &student.biology);
//计算平均成绩
float average_score = (student.chinese + student.math + student.english + student.physics + student.chemistry + student.biology) / 6;
//输出学生信息及平均成绩
printf("\n学生信息如下:\n");
printf("姓名:%s\n", student.name);
printf("学号:%d\n", student.student_id);
printf("班级:%s\n", student.class);
printf("性别:%s\n", student.gender);
printf("语文成绩:%.2f\n", student.chinese);
printf("数学成绩:%.2f\n", student.math);
printf("英语成绩:%.2f\n", student.english);
printf("物理成绩:%.2f\n", student.physics);
printf("化学成绩:%.2f\n", student.chemistry);
printf("生物成绩:%.2f\n", student.biology);
printf("平均成绩:%.2f\n", average_score);
return 0;
}
```
希望这个代码对你有所帮助!
阅读全文