C语言实现观众投票统计:调查电视台栏目受欢迎程度
#include <stdio.h>
int main() { int n, vote, count[8] = {0}; // count数组用来记录每个栏目的得票数
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%d", &vote);
count[vote - 1]++; // 注意栏目编号从1开始,所以要减1
}
for (int i = 0; i < 8; i++)
{
printf("%4d%4d\n", i + 1, count[i]); // 输出每个栏目的编号和得票数
}
return 0;
}
原文地址: https://www.cveoy.top/t/topic/jyay 著作权归作者所有。请勿转载和采集!