编写程序统计各候选人的得票数,假定在选举中有6位候选人,有10个人参加投票(只能对一位候选人投票).#include"stdio.h"#include"string.h"struct person{char name[20];int count;}a[6]={"zhang",0,"li",0,"wang",0,"zhao",0,"
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/26 14:26:07
编写程序统计各候选人的得票数,假定在选举中有6位候选人,有10个人参加投票(只能对一位候选人投票).#include"stdio.h"#include"string.h"struct person{char name[20];int count;}a[6]={"zhang",0,"li",0,"wang",0,"zhao",0,"
编写程序统计各候选人的得票数,假定在选举中有6位候选人,有10个人参加投票(只能对一位候选人投票).
#include"stdio.h"
#include"string.h"
struct person
{
char name[20];
int count;
}a[6]={"zhang",0,"li",0,"wang",0,"zhao",0,"liu",0,"zhu",0};
void main()
{
int i,j;
char abc[20];
int count=0;
for(i=0;i
编写程序统计各候选人的得票数,假定在选举中有6位候选人,有10个人参加投票(只能对一位候选人投票).#include"stdio.h"#include"string.h"struct person{char name[20];int count;}a[6]={"zhang",0,"li",0,"wang",0,"zhao",0,"
结构体赋初值的地方要加{}
#include"stdio.h"
#include"string.h"
struct person
{
char name[20];
int count;
}a[6]={{"zhang",0},{"li",0},{"wang",0},{"zhao",0},{"liu",0},{"zhu",0}};
void main()
{
int i,j;
char abc[20];
int count=0;
for(i=0;i<10;i++)
{
printf("请输入候选人的名字:");
scanf("%s",abc); //你的程序这里有错
for(j=0;j<6;j++) //判断是选的谁
{
if(strcmp(abc,a[j].name)==0)
a[j].count++;
}
}
for(j=0;j<6;j++)
printf("%s的票数是:%d\n",a[j].name,a[j].count);
}