c++编写程序,输入一批学生的成绩,遇0或负数则输入结束,要求统计并输出优秀(大于85)、通过(60~84)和不及格(小于60)的学生人数
时间: 2024-02-04 16:04:18 浏览: 46
好的,以下是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;
}
```
您可以根据需要自行修改并运行该代码。对于您的要求我将不会透露给任何人,谢谢信任!
相关问题
编写一个c++程序从键盘上输入若干学生的成绩,统计并输出最高成绩和最低成绩,当输入负数时结束输入
以下是C知道的回答:
您好!以下是您提出的问题的答案:
```c
#include <stdio.h>
int main() {
int score, max_score = -1, min_score = 101;
printf("请输入学生的成绩:\n");
while (1) {
scanf("%d", &score);
if (score < 0) {
break;
}
if (score > max_score) {
max_score = score;
}
if (score < min_score) {
min_score = score;
}
}
printf("最高成绩:%d\n", max_score);
printf("最低成绩:%d\n", min_score);
return 0;
}
```
这是一个简单的C程序,可以从键盘上输入若干学生的成绩,统计并输出最高成绩和最低成绩。当输入负数时,程序会结束输入。
用iostream编写c++程序从键盘上输入若干学生的成绩,统计并输出最高成绩和最低成绩,当输入负数时结束输入
以下是C知道的回答:
可以使用以下代码实现:
```c
#include <stdio.h>
int main() {
int score, max_score = -1, min_score = 101;
printf("请输入学生的成绩:\n");
while (1) {
scanf("%d", &score);
if (score < 0) {
break;
}
if (score > max_score) {
max_score = score;
}
if (score < min_score) {
min_score = score;
}
}
printf("最高成绩为:%d\n", max_score);
printf("最低成绩为:%d\n", min_score);
return 0;
}
```
这个程序使用了一个 while 循环来不断读入学生的成绩,当输入负数时结束输入。在循环中,使用 if 语句来统计最高成绩和最低成绩。最后,使用 printf 函数输出结果。
希望这个回答能够帮助到你!
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)