C program to check person is eligible for voting or not : To decide person eligible for voting or not
In this tutorial, we are going to see one simple program that is to check whether the person is eligible for voting or not.
For checking the eligibility for voting we have to write simple condition.
As we know, as per government the persons whose age is greater than 18 are eligible to give the vote and below age 18 are not allowed to vote.
So, using simple condition statement we check this condition and decide who is eligible and who is not eligible.
We can implement this program in two ways.
1. By taking age input from the user.
2. By taking a date of birth input from the user.
Using first method logic:-
- First, we take the input the age of the person to check eligibility for voting.
- We write the condition that is input > 18 then, if true we print person is eligible for voting
- 3 else person is not eligible.
Using second method logic:-
- Take input date of birth from the user.
- Calculate current age by date of birth of user.
- Now compare the age of person, age > 18
- If true, then a print person is eligible for voting.
- Else person is not eligible for voting.
C program to check person is eligible for voting or not
int age ;
//take input age from user
printf("Enter the age of the person: ");
//check voting eligibility
printf("person is eligible for voting");
printf("person is not eligibal for voting\n");
1. Declare variables.
age => to store age
2. Take age input.
=> age = 25
3. Check condition for vote eligibility
if (age>=18) => 25 >= 18 condition true if block executed.
printf(“person is eligible for voting”);