用c语言输出各科不及格的学生信息
时间: 2024-03-25 17:40:49 浏览: 18
好的,以下是用C语言输出各科不及格的学生信息的示例代码:
```c
#include <stdio.h>
struct student {
char name[20];
int score_math;
int score_english;
int score_chinese;
};
int main() {
struct student stu[3] = {
{"Tom", 60, 70, 80},
{"Jerry", 50, 65, 70},
{"Bob", 80, 90, 30}
};
printf("不及格学生:\n");
for (int i = 0; i < 3; i++) {
if (stu[i].score_math < 60) {
printf("%s 数学不及格\n", stu[i].name);
}
if (stu[i].score_english < 60) {
printf("%s 英语不及格\n", stu[i].name);
}
if (stu[i].score_chinese < 60) {
printf("%s 语文不及格\n", stu[i].name);
}
}
return 0;
}
```
上述代码中,我们定义了一个结构体 `student`,包含了学生的姓名和三门课程的成绩。然后我们定义了一个长度为3的结构体数组 `stu`,并初始化了其中的三个学生信息。
接下来我们使用 `for` 循环遍历 `stu` 数组,判断每个学生的三门课程成绩是否低于60分,如果是则输出该学生姓名和该科目不及格的信息。
最后我们在主函数中返回0,表示程序正常结束。