Q:

Write a C program to check whether a person is eligible for voting or not?

0

C program to check whether a person is eligible for voting or not?

Given age of a person and we have to check whether 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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Consider the program:

#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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C programming Basic Input, Output, if else, Ternary Operator based Programs

Similar questions


need a help?


find thousands of online teachers now
Write a C program to read marks and print percenta... >>
<< Write a C program to find Largest Number among thr...