有40个学生被邀请给自助餐厅的食品和服务质量打分(1~5等级),统计调查结果,并用*打印如下形式的统计结果
#includestdio.h
int main()
{
/*统计结果表示*/
char* stars[10] = {"*",
"**",
"***",
"****",
"*****",
"******",
"*******",
"********",
"*********",
"**********"};
/*投票*/
int grade[] = {3,4,2,5,6,7,8,5,2,2,
1,3,5,6,7,8,9,10,2,2,
3,4,5,6,7,8,9,10,8,7,
6,5,4,5,6,7,8,7,6,5};
/*投票结果*/
int result[10];
for(int i = 0; i 10; i++)
{
result[i] = 0;
}
for(int i = 0; i 40; i++)
{
result[grade[i]-1]++;
}
printf("grade\tCount Histogram \n");
for(int i = 0; i 10; i++)
{
if( result[i] == 0 ) continue;
printf( "%d\t%s\n", i+1, stars[ result[i]-1 ] );
}
}
有40个学生被邀请给自助餐厅的食品和服务质量打分(1~5等级),统计调查结果,并用*打印如下形式的统计结果
#includestdio.h
int main()
{
/*统计结果表示*/
char* stars[10] = {"*",
"**",
"***",
"****",
"*****",
"******",
"*******",
"********",
"*********",
"**********"};
/*投票*/
int grade[] = {3,4,2,5,6,7,8,5,2,2,
1,3,5,6,7,8,9,10,2,2,
3,4,5,6,7,8,9,10,8,7,
6,5,4,5,6,7,8,7,6,5};
/*投票结果*/
int result[10];
for(int i = 0; i 10; i++)
{
result[i] = 0;
}
for(int i = 0; i 40; i++)
{
result[grade[i]-1]++;
}
printf("grade\tCount Histogram \n");
for(int i = 0; i 10; i++)
{
if( result[i] == 0 ) continue;
printf( "%d\t%s\n", i+1, stars[ result[i]-1 ] );
}
}