c语言用循环结构编写程序,计算所有学生的平均成绩并统计成绩在80到90分(不含90)之间的人数
时间: 2023-05-23 15:01:59 浏览: 144
可以使用以下代码求解:
```
#include <stdio.h>
int main() {
// 学生人数
int num;
printf("请输入学生人数:");
scanf("%d", &num);
// 总成绩
float sum = 0;
// 80~90分之间的人数
int count = 0;
// 逐个输入成绩并计算总成绩和符合条件的人数
for (int i = 1; i <= num; i++) {
float score;
printf("请输入第%d个学生的成绩:", i);
scanf("%f", &score);
sum += score;
if (score >= 80 && score < 90) {
count++;
}
}
// 计算平均成绩并输出结果
float avg = sum / num;
printf("平均成绩为:%.2f,80~90分之间的人数为:%d\n", avg, count);
return 0;
}
```
相关问题
c语言编写程序,计算所有学生的平均成绩并统计成绩在80到90分(不含90)之间的人数
可以使用数组存储学生成绩,然后遍历数组求出平均值和在80到90分之间的人数。以下是示例代码:
```c
#include <stdio.h>
int main() {
float scores[100];
int n, count = 0;
float sum = 0, avg;
printf("请输入学生人数:");
scanf("%d", &n);
printf("请输入%d个学生成绩:\n", n);
for (int i = 0; i < n; i++) {
scanf("%f", &scores[i]);
sum += scores[i];
if (scores[i] >= 80 && scores[i] < 90) {
count++;
}
}
avg = sum / n;
printf("平均成绩为:%.2f\n", avg);
printf("成绩在80到90分之间的人数为:%d\n", count);
return 0;
}
```
注意:以上代码中使用了硬编码的数组大小,实际使用时应该根据学生人数动态分配数组大小。
c语言本题要求编写程序,计算学生们的平均成绩,并统计不及格人数。题目保证输入输出均在整型范围内。
好的,下面是一个简单的 C 语言程序,可以帮助你计算学生们的平均成绩,并统计不及格人数:
```c
#include <stdio.h>
int main() {
int n, sum = 0, fail = 0;
scanf("%d", &n); // 输入学生数量
for (int i = 0; i < n; i++) {
int score;
scanf("%d", &score); // 输入学生的成绩
sum += score; // 累加学生的成绩
if (score < 60) {
fail++; // 统计不及格人数
}
}
printf("平均成绩为:%d\n", sum / n); // 输出平均成绩
printf("不及格人数为:%d\n", fail); // 输出不及格人数
return 0;
}
```
这个程序使用了一个 `for` 循环来读取每个学生的成绩,并且根据成绩是否小于 60 来统计不及格人数。最后,程序输出了平均成绩和不及格人数。你可以将程序复制粘贴到 C 语言编译器中运行测试。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)