/* Note:Your choice is C IDE */ #include "stdio.h" #include "string.h" void main() { int zs,ls,ww,zl;//定义一个给参选人员的票数 int max;// int xuhao;// char name[5];//参选人员的名字 zs=ls=ww=zl=0;//初始票数都为0 printf("候选人名单如下 "); printf("1.张三 "); printf("2.李四 "); printf("3.王五 "); printf("4.赵六 "); for(;xuhao!=0;)//判断条件 循环语句 { printf("请输入候选人的编号(输0表示投票结束)"); ss: scanf("%d",&xuhao);// switch(xuhao)// { case 1:zs++;break; case 2:ls++;break; case 3:ww++;break; case 4:zl++;break; case 0:break; default:printf("无此候选人,请重输:"); fflush(stdin); goto ss; break; } } printf("选举票数如下 "); printf("张三%d票 ",zs); printf("李四%d票 ",ls); printf("王五%d票 ",ww); printf("赵六%d票 ",zl); if(zs>ls) { max=zs; strcpy(name,"张三"); } else { max=ls; strcpy(name,"李四"); } if(ww>max) { max=ww; strcpy(name,"王五"); } if(zl>max) { max=zl; strcpy(name,"赵六"); } printf("%s当班长",name); }