int cnt; //cnt存放弃权票数,cnt分别存放每个人的得票
int i,n;
for(i = 0; i <= 5; ++) //得票数初始化为0
cnt[i] = 0;
for(i=0; i < 30; i++) //30个人
{
scanf("%d",&n);
if(n<0 || n>5)
{
printf("输入有误,视为弃权");
cnt++;
}
else
cnt[i]++;
}
for(i = 1; i <= 5; i++)
printf("候选人%d得票数:\n", i, cnt[i]);
printf("弃权票数:\n", cnt);
# include
# include
int main()
{
int cadidate={0};//五个候选人;
int N=30;//三十个选民;
int i;
int op;//投票选项
int abstention=0;//弃权
for(i=0; i
{
scanf("%d",&op);
switch(op)
{
case 1: cadidate++;break;
case 2: cadidate++;break;
case 3: cadidate++;break;
case 4: cadidate++;break;
case 5: cadidate++;break;
case 0: abstention++; break;
default:return -1;
}
}
for(i=0; i<5; i++)
printf("第%d位候选者获得选票%d张。\n",i+1,cadidate[i]);
printf("弃权票%d张。\n",abstention);
return 0;
}
标签:编程