Home »
        C solved programs »
        C basic programs
    
    C program to check whether a person is eligible for voting or not?
    
    
    
    
        In this program, we are going to learn how to check that, a person is eligible for voting or not, when age is given or input through the user?
        
            Submitted by Manju Tomar, on October 13, 2017
        
    
    Problem statement
    Given age of a person and we have to check whether person is eligible for voting or not.
    Logic to check whether a person is eligible for voting or not
    To check that a person is eligible for voting or not, we need to check whether person's age is greater than or equal to 18. For this we are reading age in a variable a and checking the condition a>=18, if the condition is true, "person will be eligible for voting" else not.
    C program to check whether a person is eligible for voting or not
#include<stdio.h>
int main()
{
	int a ;
	
	//input age
	printf("Enter the age of the person: ");
	scanf("%d",&a);
	//check voting eligibility
	if (a>=18)
	{
		printf("Eigibal for voting");
	}
	else
	{
		printf("Not eligibal for voting\n");
	}	
	return 0;
}
Output
First run:
Enter the age of the person: 21
Eigibal for voting
Second run:
Enter the age of the person: 15
Not eligibal for voting
    
    It's a simple program and I hope your concept of checking a condition may clear, if there is any mistake then write your comment in the comment box. 
	C Basic Programs »
	
    
    
    
    
    
  
    Advertisement
    
    
    
  
  
    Advertisement