声明一个存放学生某选修课信息的结构体类型,包括:姓名、学号、年级、院系、成绩,要求在随意输入3个学生数据后,按照学号顺序输出学生信息;然后由用户输入院系名称,统计该院学生人数,并显示成绩不及格的学生信息(成绩小于60分)。用c语言给出完整代码,不需要解释
时间: 2023-02-06 19:55:46 浏览: 121
C语言学生选修课管理系统.rar
#include <stdio.h>
#include <string.h>
struct Student {
char name[20];
int stu_id;
int grade;
char department[20];
int score;
};
int main() {
struct Student students[3];
for (int i = 0; i < 3; i++) {
printf("请输入第%d个学生的信息:\n", i + 1);
printf("姓名: ");
scanf("%s", students[i].name);
printf("学号: ");
scanf("%d", &students[i].stu_id);
printf("年级: ");
scanf("%d", &students[i].grade);
printf("院系: ");
scanf("%s", students[i].department);
printf("成绩: ");
scanf("%d", &students[i].score);
}
// 按照学号顺序输出学生信息
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3 - i - 1; j++) {
if (students[j].stu_id > students[j + 1].stu_id) {
struct Student temp = students[j];
students[j] = students[j + 1];
students[j + 1] = temp;
}
}
}
printf("按照学号顺序输出学生信息:\n");
for (int i = 0; i < 3; i++) {
printf("学号: %d\n", students[i].stu_id);
printf("姓名: %s\n", students[i].name);
printf("年级: %d\n", students[i].grade);
printf("院系: %s\n", students[i].department);
printf("成绩: %d\n", students[i].score);
}
char department[20];
printf("请输入院系名称: ");
scanf("%s", department);
int count = 0;
printf("成绩不及格的学生信息:\n");
for (int i = 0; i < 3; i++) {
if (strcmp(students[i].department, department) == 0 && students[i].score < 60) {
printf("学号: %d\n", students[i].stu_id);
printf("姓名: %s\n", students[i].name);
printf("年级: %d\n", students[i].grade);
printf("院系: %s\n", students[i].department);
阅读全文