Programming Examples

Write a program to count number of votes secured by A and B


Write a program to count number of votes secured by ‘A’ & ‘B’. Assume three voters are voting them. Also count the invalid votes

Solution

# include <stdio.h>
void main()
{
int a=0,b=0,o=0,i;
char v;
clrscr();
printf(“\tPress A or B\n”);
for(i=1;i<=3;i++)
{
 printf(“\n\nVoter no. %d”,i);
 printf(“Enter Vote :”);
 v=getche();
 v=toupper(v);
 if(v==‘A’)
 a++;
 else if(v==‘B’)
 b++;
 else
 o++;
}
printf(“\n\n Status of vote(s) \n”);
printf(“\nA secures %d vote(s).”,a);
printf(“\nB secures %d vote(s).”,b);
printf(“\nInvalid votes %d.”,o);
getch();
}
Output

OUTPUT:

Press A or B

Voter no. 1 Enter Vote :A

Voter no. 2 Enter Vote :A

Voter no. 3 Enter Vote :A

Status of vote(s)

A secures 3 vote(s).

B secures 0 vote(s).

Invalid votes 0.

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz