Implemented with a struct array: There are three candidates, each voter can only choose one person, write a ballot procedure, and eventually output the candidate's votes (assuming there are 10 voters) #include <stdio.h> #include <stdio.h>struct Person //declares struct {char name[20];int count;} Leader[3]={"Li", 0, "Zhang", 0, "Sun", 0}; Defines an array of structs and initializes int main () {int I,j;char leader_name[20]; Define character array printf ("Please enter candidate Name: li,zhang,sun\n"); for (i=0;i<10;i++) {scanf ("%s", leader_name); The voter enters the candidate name for (j=0;j<3;j++) {if (strcmp (leader_name,leader[j].name) ==0) //If the name corresponds, the name is added 1leader[j].count++;}} printf ("\ nthe final poll result: \ n"); for (i=0;i<3;i++) {printf ("%13s:%d\n", Leader[i].name,leader[i].count);} return 0;}
The "C language" is implemented with a struct array: There are three candidates, each voter can only choose one person, write a ballot procedure, and ultimately output the number of votes of the candidate