w3resource

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?

Test your Programming skills with w3resource's quiz.



C Programming: Tips of the Day

Why do C and C++ compilers allow array lengths in function signatures when they're never enforced?

It is a quirk of the syntax for passing arrays to functions.

Actually it is not possible to pass an array in C. If you write syntax that looks like it should pass the array, what actually happens is that a pointer to the first element of the array is passed instead.

Since the pointer does not include any length information, the contents of your [] in the function formal parameter list are actually ignored.

Ref : https://bit.ly/3fhlvdH