C语言编写程序,输入一批学生的成绩,遇0或负数则输入结束,要求统计并输出优秀(大于85)、通过(60~84)和不及格(小于60)的学生人数
时间: 2024-05-14 08:16:46 浏览: 16
您好!非常感谢您对ChitGPT的信任和支持。
关于您的问题,以下是C语言程序的实现:
```c
#include <stdio.h>
int main() {
int score, excellent = 0, pass = 0, fail = 0;
printf("请输入学生成绩(遇0或负数结束输入):\n");
while (1) {
scanf("%d", &score);
if (score <= 0) {
break;
}
if (score > 85) {
excellent++;
} else if (score >= 60) {
pass++;
} else {
fail++;
}
}
printf("优秀:%d人\n", excellent);
printf("通过:%d人\n", pass);
printf("不及格:%d人\n", fail);
return 0;
}
```
希望您对这个答案满意,如果您还有其他问题,欢迎随时提出!
相关问题
编写c语言程序,输入一批学生的成绩,遇 0 或负数则输入结束,要求统计并输出优秀(大于等 于 85)、通过(60—84)和不及格(小于 60)的学生人数,0 不计算入内。
好的,以下是C语言程序的代码:
```c
#include <stdio.h>
int main() {
int score, excellent = 0, pass = 0, fail = 0;
printf("请输入学生的成绩:\n");
while (1) {
scanf("%d", &score);
if (score <= 0) {
break;
} else if (score >= 85) {
excellent++;
} else if (score >= 60 && score <= 84) {
pass++;
} else {
fail++;
}
}
printf("优秀的学生人数:%d\n", excellent);
printf("通过的学生人数:%d\n", pass);
printf("不及格的学生人数:%d\n", fail);
return 0;
}
```
程序中首先定义了变量`score`、`excellent`、`pass`、`fail`,分别表示学生的成绩、优秀人数、通过人数、不及格人数。然后通过`while`循环输入学生的成绩并根据成绩的区间统计相应的人数,遇到输入的0或负数则结束循环。最后输出统计结果即可。
注意:程序中使用了死循环`while(1)`,可以通过输入非正整数来结束循环。也可以使用其它方式结束循环,比如在循环中加入`break`语句。
c++编写程序,输入一批学生的成绩,遇0或负数则输入结束,要求统计并输出优秀(大于85)、通过(60~84)和不及格(小于60)的学生人数
好的,以下是C语言代码,可实现输入一批学生的成绩并统计不同分数段的人数:
```c
#include <stdio.h>
int main() {
int score, excellent = 0, pass = 0, fail = 0;
printf("请输入学生的成绩:\n");
scanf("%d", &score);
while(score > 0) {
if(score > 85) {
excellent++;
}
else if(score >= 60) {
pass++;
}
else {
fail++;
}
scanf("%d", &score);
}
printf("优秀学生人数:%d\n", excellent);
printf("通过学生人数:%d\n", pass);
printf("不及格学生人数:%d\n", fail);
return 0;
}
```
您可以根据需要自行修改并运行该代码。对于您的要求我将不会透露给任何人,谢谢信任!
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)