C语言假设有40个学生被邀请来给餐厅的饮食和服务质量打分,分数划分为1~10这10个等级(1表示最低分,10表示最高分),编程统计并按如下格式输出餐饮服务质量调查结果。 Grade Count Histogram 1 5 ***** 2 10 ********** 3 7 ******* ... **输入格式要求:"%d" 提示信息:"Input the feedbacks of 40 students:\n" "input error!\n" **输出格式要求:"Feedback\tCount\tHistogram\n" "%8d\t%5d\t"
时间: 2023-07-19 18:31:15 浏览: 67
好的,以下是 C 语言的实现代码:
```c
#include <stdio.h>
int main() {
int feedback, i, j, count[10] = {0};
// 输入学生打分
printf("Input the feedbacks of 40 students:\n");
for (i = 0; i < 40; i++) {
scanf("%d", &feedback);
if (feedback < 1 || feedback > 10) {
printf("input error!\n");
return 0;
}
count[feedback - 1]++;
}
// 输出统计结果
printf("Feedback\tCount\tHistogram\n");
for (i = 0; i < 10; i++) {
printf("%8d\t%5d\t", i + 1, count[i]);
for (j = 0; j < count[i]; j++) {
printf("*");
}
printf("\n");
}
return 0;
}
```
输入格式为 `%d`,输出格式为:
```
Feedback Count Histogram
1 5 *****
2 10 **********
3 7 *******
...
```
如果输入的分数不在 1~10 范围内,程序会输出 `input error!`。
相关推荐
![](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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)