C program to Check if a Person is Eligible to Vote
Subject: PPS (Programming for Problem Solving)
Contributed By: Sanjay
Created At: February 3, 2025
Question:
Write a C program to Check if a Person is Eligible to Vote
Explanation Video:

Explanation:
C Program for Vote Eligibility:
Basic info: if a person's age is greater than 18, then he is eligible to vote.If age<18 then not eligible.
Here to check the age and decide whether a person is eligible or not, we simply need to compare if age≥18
.
First Let's Build The Logic:
if age ≥ 18
(age greater than or equal to 18): Eligible to vote
else: Not Eligible to Vote
Let's develop a C program for the above logic:
- First, we need to take the age as input from the user:
int age;
printf("Enter your age: ");
scanf("%d", &age)
- Then we need to compare the age using the
if-else
condition and print the output:
if (age >= 18)
printf("You are eligible to vote.\n");
else
printf("You are not eligible to vote.\n");
Source Code:
#include <stdio.h>
int main() {
int age;
printf("Enter your age: ");
scanf("%d", &age);
if (age >= 18)
printf("You are eligible to vote.\n");
else
printf("You are not eligible to vote.\n");
return 0;
}
Input:
CASE-1:
Enter your age: 17
CASE-2:
Enter your age: 29
Output:
CASE-1:
You are not eligible to vote.
CASE-2:
You are eligible to Vote.