C Program To Input User’s Age And Display A Message You Can Vote Or Cannot Vote.

Q16. Write a C program to input user’s age and display a message you can vote or cannot vote.

Solution:

#include<stdio.h> //standard input/output header file

#include<conio.h> //for clrscr()

 

int main()

{

int age;

 

clrscr(); //for clearing the screen

 

printf(“\n Enter your age: “);

scanf(“%d”,&age);

 

age>=18?printf(“\n You can vote.”) :printf(“\n You cannot vote.”);

 

getch(); //holds the screen until any key is pressed

return 0; //makes main() finish

}

 

OUTPUT:

CASE 1:

Enter your age: 7

 

You cannot vote.

 

CASE 2:

Enter your age: 28

 

You can vote.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: