w3resource logo


C Programming Exercises

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

Secondary Nav

C Conditional Statement: Exercise-5 with Solution

Write a C program to read age of a candiadte and detrermine whether it is eligible for casting his/her own vote.
Test Data :
21 
Expected Output
:
Congratulation! You are eligible for casting your vote.. 

Sample Solution :-

Flowchart :

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");

}

Code Editor :

#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");

}

Improve this sample solution and post your code through Disqus.



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

PHP: Loop

JavaScript: Delete duplicates in an array

Oracle: Round the number