用C语言编写程序,根据每位同学的总成绩判断其是否通过考试(总成绩大于等于240为通过这三名学生考试的数据如下:106,“zhang",89,96,88 107,"wang",79,86,91 109,"zhao",78,65,67
时间: 2024-03-05 11:09:21 浏览: 23
可以使用以下的C语言代码实现:
```c
#include <stdio.h>
int main() {
// 定义学生数据
int id1 = 106, total1 = 89 + 96 + 88;
int id2 = 107, total2 = 79 + 86 + 91;
int id3 = 109, total3 = 78 + 65 + 67;
// 判断是否通过考试
if (total1 >= 240) {
printf("%d %s passed the exam.\n", id1, "zhang");
} else {
printf("%d %s failed the exam.\n", id1, "zhang");
}
if (total2 >= 240) {
printf("%d %s passed the exam.\n", id2, "wang");
} else {
printf("%d %s failed the exam.\n", id2, "wang");
}
if (total3 >= 240) {
printf("%d %s passed the exam.\n", id3, "zhao");
} else {
printf("%d %s failed the exam.\n", id3, "zhao");
}
return 0;
}
```
输出结果为:
```
106 zhang failed the exam.
107 wang failed the exam.
109 zhao failed the exam.
```
因为三个学生的总成绩都不到240分,所以他们都没有通过考试。