请使用c语言,输入一个班10个学生的学号姓名和每个学生考试四门课程(程序设计、数据库、网络基础、英语)的成绩,
时间: 2023-12-16 20:20:09 浏览: 85
好的,以下是一个示例程序,可以实现您的需求:
```c
#include <stdio.h>
struct student{
int id;
char name[20];
float score[4];
};
int main(){
struct student stu[10];
int i;
// 输入学生信息
for(i = 0; i < 10; i++){
printf("请输入第%d个学生的信息:\n", i+1);
printf("学号:");
scanf("%d", &stu[i].id);
printf("姓名:");
scanf("%s", stu[i].name);
printf("程序设计成绩:");
scanf("%f", &stu[i].score[0]);
printf("数据库成绩:");
scanf("%f", &stu[i].score[1]);
printf("网络基础成绩:");
scanf("%f", &stu[i].score[2]);
printf("英语成绩:");
scanf("%f", &stu[i].score[3]);
}
// 输出学生信息
printf("\n学号\t姓名\t程序设计\t数据库\t网络基础\t英语\n");
for(i = 0; i < 10; i++){
printf("%d\t%s\t%.2f\t\t%.2f\t%.2f\t\t%.2f\n", stu[i].id, stu[i].name, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].score[3]);
}
return 0;
}
```
程序中定义了一个 `struct student` 结构体,用于保存学生的信息,包括学号、姓名和四门课程的成绩。在 `main` 函数中,循环输入每个学生的信息,并保存在 `stu` 数组中。然后再循环输出每个学生的信息,包括学号、姓名和四门课程的成绩。
注意,在输入学生信息时,需要使用循环语句,并且需要逐个输入每个学生的信息。在输出学生信息时,使用了格式化输出函数 `printf`,可以设置输出格式,使输出更加清晰易读。
阅读全文