c语言实现:任意输入某个班级全部同学的某门课成绩,输出某个分数段统计的人数假设班级人数为10
时间: 2023-05-25 18:06:20 浏览: 63
#include <stdio.h>
int main() {
float scores[10]; // 存储10个同学的成绩
int count = 0; // 统计某个分数段的人数
float lower, upper; // 分数段的下限和上限
// 输入10个同学的成绩
printf("请输入10个同学的成绩:\n");
for (int i = 0; i < 10; i++) {
printf("请输入第%d名同学的成绩:", i+1);
scanf("%f", &scores[i]);
}
// 输入分数段的下限和上限
printf("请输入分数段的下限和上限:\n");
scanf("%f%f", &lower, &upper);
// 统计分数在指定区间的人数
for (int i = 0; i < 10; i++) {
if (scores[i] >= lower && scores[i] <= upper) {
count++;
}
}
// 输出统计结果
printf("分数在%.2f和%.2f之间的人数是:%d\n", lower, upper, count);
return 0;
}
相关问题
C语言:统计一门课程各分数段人数:统计一个班级一门课程各分数段人数,班级人数自定,成绩为百分制整数。
好的,我可以回答这个问题。为了统计各分数段人数,需要先确定分数段范围。例如,我们可以将分数分为60以下、60-69、70-79、80-89、90以上五个分数段。然后,遍历所有学生的成绩,将每个成绩所在的分数段计数器加1。最后,输出各个分数段的计数器值即可。以下是一个C语言实现的例子:
```c
#include <stdio.h>
int main() {
int num_students = 0, score;
int count_60down = 0, count_60to69 = 0, count_70to79 = 0, count_80to89 = 0, count_90up = 0;
printf("请输入班级人数:\n");
scanf("%d", &num_students);
printf("请依次输入每个学生的成绩(整数):\n");
for (int i = 0; i < num_students; i++) {
scanf("%d", &score);
if (score < 60) {
count_60down++;
} else if (score < 70) {
count_60to69++;
} else if (score < 80) {
count_70to79++;
} else if (score < 90) {
count_80to89++;
} else {
count_90up++;
}
}
printf("各分数段人数如下:\n");
printf("60以下:%d\n", count_60down);
printf("60-69:%d\n", count_60to69);
printf("70-79:%d\n", count_70to79);
printf("80-89:%d\n", count_80to89);
printf("90以上:%d\n", count_90up);
return 0;
}
```
这个例子中,首先通过`scanf`获取班级人数。然后,通过一个循环,遍历每位学生的成绩,并根据分数范围计数。最后,输出各个分数段的计数值。
C语言输入一个班级某门课程的成绩,统计并 输出全班该门课程的平均成绩
以下是一个简单的C语言程序,可以输入一个班级某门课程的成绩,并计算出全班该门课程的平均成绩。
```c
#include <stdio.h>
int main()
{
int n; // 学生人数
int sum = 0; // 成绩总和
int score; // 学生成绩
printf("请输入学生人数:");
scanf("%d", &n);
for (int i = 0; i < n; i++) {
printf("请输入第%d个学生的成绩:", i+1);
scanf("%d", &score);
sum += score;
}
printf("全班该门课程的平均成绩为:%.2f\n", (float)sum / n);
return 0;
}
```
在这个程序中,我们首先使用`scanf()`函数从用户那里获取班级人数`n`。然后,我们使用`for`循环来迭代每个学生的成绩,并将它们加起来存储在变量`sum`中。最后,我们使用`printf()`函数输出全班该门课程的平均成绩,即平均成绩等于总成绩除以学生人数。注意,我们使用了类型转换`(float)`将`sum`转换为浮点数,以确保我们得出的平均成绩是一个浮点数。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)