输入某班学生某门课的成绩(最多不超过40人,具体人数由用户键盘输入),用C语言编程统计不及格人数。 **输入格式要求:"%d" 提示信息:"How many students?" **输出格式要求:"Fail students = %d\n" 程序运行示例如下: How many students?5 45 56 78 99 100 Fail students = 2
时间: 2023-12-03 12:04:42 浏览: 144
c代码-从键盘输入一个班(全班人数在15~20之间)学生某门课的成绩,当输入成绩为负值时,输入结束,分别实现下列功能: (1)录入每个学生的学号(学号:2016001~2016020)和考试成绩; (2)计算课程的总分和平均分;
5星 · 资源好评率100%
下面是代码实现:
```c
#include <stdio.h>
int main() {
int num, fail_count = 0;
printf("How many students? ");
scanf("%d", &num);
int scores[num];
for (int i = 0; i < num; i++) {
scanf("%d", &scores[i]);
if (scores[i] < 60) {
fail_count++;
}
}
printf("Fail students = %d\n", fail_count);
return 0;
}
```
程序运行示例如下:
```
How many students? 5
45
56
78
99
100
Fail students = 2
```
阅读全文