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.
- By taking age input from the user.
- 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");
Enter the age of the person: 21
the person is eligible for voting
Other solved programs
- Numeric Pyramid Program in C With Explanation
- Alphabet Pyramid Programs in C
- How to Implement A Priority Queue in C
- Palindrome using string function
- Fibonacci Series
- Factorial of Given Number