w3resource
C Programming Exercises

C Exercises: Detrermine a specific age is eligible for casting the vote

C Conditional Statement: Exercise-5 with Solution

Write a C program to read the age of a candiadte and detrermine whether it is eligible for casting his/her own vote.

Pictorial Presentation:

Detrermine a specific age is eligible for casting the vote

Sample Solution:

C Code :

#include <stdio.h>
void main()
{
  int vote_age;

  printf("Input the age of the candidate : ");
  scanf("%d",&vote_age);
  if (vote_age<18)
     {
       printf("Sorry, You are not eligible to caste your vote.\n");
       printf("You would be able to caste your vote after %d year.\n",18-vote_age);
     }
  else
     printf("Congratulation! You are eligible for casting your vote.\n");
}

Sample Output:

Input the age of the candidate : 21                                                                           
Congratulation! You are eligible for casting your vote.

Flowchart:

Detrermine a specific age is eligible for casting the vote.

C Programming Code Editor:

Improve this sample solution and post your code through Disqus.

Previous: Write a C program to find whether a given year is a leap year or not.
Next: Write a C program to read the value of an integer m and display the value of n is 1 when m is larger than 0, 0 when m is 0 and -1 when m is less than 0.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming