C

Write a C Program to check whether a Person is eligible to Vote or not2 min read

Here’s an example of a C program that checks whether a person is eligible to vote or not:

This program uses the C standard library and specifically stdio.h and uses input and output functions. Here’s a step by step explanation of what the code does:

  1. The program starts by including the stdio.h header, which provides access to the standard input and output functions in C such as printf and scanf.
  2. The main() function is the entry point of the program. Inside the main function, it declares an integer variable age.
  3. It uses printf function to prompt the user to enter their age and scanf function to read the user input and store it in the variable age.
  4. Next, it uses an if-else statement to check if the value of the age variable is greater than or equal to 18. If the condition is true, the program prints a message “You are eligible to vote.” to indicate that the person is eligible to vote.
  5. If the condition is false, the program prints a message “You are not eligible to vote.” to indicate that the person is not eligible to vote.
  6. The return 0 statement at the end of the main function is used to indicate that the program has executed successfully.




This program prompts the user to enter their age and uses an if-else statement to check if the person is eligible to vote or not based on their age. It will give the output as per the condition written in the code i.e if the entered age is greater than or equal to 18, it will give the message ‘You are eligible to vote’ otherwise ‘You are not eligible to vote’.

It is important to note that different countries have different voting age requirement, in most countries 18 is the age limit but this may not be the case in every country.

The output of this program will be a string of text displayed on the console, depending on the input provided by the user.

When the program is executed, it will prompt the user to enter their age. For example, if the user enters 20, the output will be:

And if the user enters 15, the output will be:

It’s worth noting that the output of this program solely depends on the input provided by the user.

Leave a Comment