Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Program to take input of 5 candidates vote and display it using an array

Posted By: Renee Lane     Category: C Programming     Views: 3405

Program to take input of 5 candidates vote and display it using an array

Code for Program to take input of 5 candidates vote and display it using an array in C Programming

#include<stdio.h>
#include<conio.h>
void main()
{
    int count[6],mark,bn,i;
    clrscr();
    for(i=0;i<=5;i++)
    {
        count[i]=0;
    }
    printf("Enter total ballot :- ");
    scanf("%d",&bn);
    for(i=0;i<=bn-1;i++)
    {
        printf("Enter your vote to candidate :- ");
        scanf("%d",&mark);
        if(mark==1)
        {
            ++count[0];
        }
        elseif(mark==2)
        {
            ++count[1];
        }
        elseif(mark==3)
        {
            ++count[2];
        }
        elseif(mark==4)
        {
            ++count[3];
        }
        elseif(mark==5)
        {
            ++count[4];
        }
        else
        {
            ++count[5];
        }

    }
    printf("\nCandidate 1's ballot :- %d",count[0]);
    printf("\nCandidate 2's ballot :- %d",count[1]);
    printf("\nCandidate 3's ballot :- %d",count[2]);
    printf("\nCandidate 4's ballot :- %d",count[3]);
    printf("\nCandidate 5's ballot :- %d",count[4]);
    printf("\nSpoilt Ballot :- %d",count[5]);
    getch();
}

/*
*********
OUTPUT
*********

Enter total ballot :- 5
Enter your vote to candidate :- 1
Enter your vote to candidate :- 3
Enter your vote to candidate :- 5
Enter your vote to candidate :- 2
Enter your vote to candidate :- 3

Candidate 1's ballot :- 1
Candidate 2's ballot :- 1
Candidate 3's ballot :- 2
Candidate 4's ballot :- 0
Candidate 5's ballot :- 1
Spoilt Ballot :- 0
*/
  
Share: 



Renee Lane
Renee Lane author of Program to take input of 5 candidates vote and display it using an array is from Wichita , United States. Renee Lane says

 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!