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

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.