c语言请对某次考试的分数,统计各分数段人数,统计原则:分别对10分以下、10-19分、20-29分、30-39分、40-49分、50-59分、60-69分、70-79,80-89分,90到99分,100分为一段,共11段 。 注意:如果输入分数不在[0,100]之间,不参与统计。 输入格式: 先输入一个整数n,表示将输入n个分数。 再输入n个分数,范围在[0~100]. 每个数用空格间隔。 输出格式: 每一行输出一个分数段的人数统计结果。分数段用0~10表示。
时间: 2023-07-14 18:12:15 浏览: 719
以下是实现该功能的C语言代码:
```c
#include <stdio.h>
int main() {
int n;
int score, count[11] = {0}; // 记录各分数段人数的数组,初始值为0
scanf("%d", &n); // 输入n个分数
for (int i = 0; i < n; i++) {
scanf("%d", &score);
if (score >= 0 && score <= 100) { // 判断分数是否在[0,100]之间
count[score / 10]++;
}
}
// 输出各分数段人数
for (int i = 0; i <= 10; i++) {
if (i == 10) { // 最后一段分数是100
printf("100: %d\n", count[10]);
} else {
printf("%d-%d: %d\n", i * 10, i * 10 + 9, count[i]);
}
}
return 0;
}
```
注释已经写得比较详细了,主要思路是:用一个长度为11的数组count记录各分数段人数,输入每个分数时将对应分数段人数加1,最后输出各分数段人数。
相关问题
用函数统计各分数段人数c语言,excel统计各分数段人数的函数
在C语言中,可以使用以下代码来统计各分数段人数:
```c
#include <stdio.h>
void countScore(int scores[], int n) {
int count[6] = {0}; // 分数段人数计数器
for (int i = 0; i < n; i++) {
if (scores[i] < 60) {
count[0]++;
} else if (scores[i] < 70) {
count[1]++;
} else if (scores[i] < 80) {
count[2]++;
} else if (scores[i] < 90) {
count[3]++;
} else if (scores[i] < 100) {
count[4]++;
} else {
count[5]++;
}
}
printf("0-59分人数:%d\n", count[0]);
printf("60-69分人数:%d\n", count[1]);
printf("70-79分人数:%d\n", count[2]);
printf("80-89分人数:%d\n", count[3]);
printf("90-99分人数:%d\n", count[4]);
printf("100分人数:%d\n", count[5]);
}
int main() {
int scores[] = {78, 92, 55, 67, 80, 88, 99, 73, 61, 100};
int n = sizeof(scores) / sizeof(scores[0]);
countScore(scores, n);
return 0;
}
```
在Excel中,可以使用以下函数来统计各分数段人数:
```excel
=COUNTIFS(A1:A10, "<60") // 统计0-59分人数
=COUNTIFS(A1:A10, ">=60", A1:A10, "<70") // 统计60-69分人数
=COUNTIFS(A1:A10, ">=70", A1:A10, "<80") // 统计70-79分人数
=COUNTIFS(A1:A10, ">=80", A1:A10, "<90") // 统计80-89分人数
=COUNTIFS(A1:A10, ">=90", A1:A10, "<100") // 统计90-99分人数
=COUNTIFS(A1:A10, ">=100") // 统计100分人数
```
其中,A1:A10是存放分数数据的单元格范围。
C语言:编写程序,由键盘任意输入10个学生的成绩,分别统计各分数段的百分比。
好的,让我来回答您的问题。以下是C语言编写的程序,可以统计各个分数段的百分比。
```c
#include <stdio.h>
int main() {
int scores[10];
int i, j, count[5];
float percent[5];
// 从键盘读取10个成绩
printf("请输入10个学生的成绩:\n");
for (i = 0; i < 10; i++) {
scanf("%d", &scores[i]);
}
// 统计各个分数段的个数
for (i = 0; i < 5; i++) {
count[i] = 0;
for (j = 0; j < 10; j++) {
if (scores[j] >= (i * 20) && scores[j] < ((i + 1) * 20)) {
count[i]++;
}
}
}
// 计算各个分数段的百分比
for (i = 0; i < 5; i++) {
percent[i] = (count[i] * 100.0) / 10.0;
}
// 输出结果
printf("\n各分数段的百分比如下:\n");
for (i = 0; i < 5; i++) {
printf("成绩在 %d - %d 分之间的学生占总人数的 %.2f%%\n", i*20, (i+1)*20-1, percent[i]);
}
return 0;
}
```
运行程序后,您可以依次输入10个学生的成绩,程序将自动输出各个分数段的百分比。希望能够帮到您!
相关推荐
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.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)