ad

Monday, February 24, 2025

C Program to Check Whether a People is Eligible to Vote or Not

                     C Program  

C Program to Check Whether a People is Eligible to Vote or Not


C Program to Check Whether a People is Eligible to Vote or Not  

Example  :-

#include<stdio.h>
 #include<conio.h>
int main()
{
int age;
clrscr();
 printf("enter your age :-");
scanf("%d", &age);
if(age>=18)
{
printf("you are eligible to vote");
}
else
{
printf("you are not eligible for vote");
}
getch();
return 0;
}


C Program to Check Whether a People is Eligible to Vote or Not  

Explain Program

Step :1

      #include <stdio.h>

use input/output library for functions like printf() and scanf().

Step :2

     int main() {

  int main is use Start of the main function the execution.

Step :3

int age;

  • Declares an integer variable named age.
  •  used to store the age input by the user

Step :4

printf("enter your age :-");

  • Displays the message “enter your age :-” on the screen.
  •  user to enter their age.

Step :5

scanf("%d", &age);

  • Reads an integer input from the user.
  • %d tells scanf to expect an integer.
  • &age is the address of the variable age, where the entered value will be stored.

Step :6

if (age >= 18)

  •  user's age  greater than or equal to 18.
  • If true, it mean the person is eligible to vote.

Step :7

{

 printf("you are eligible to vote"); 

}

  • If the condition is true (age >= 18), this message is printed.

Step :8

else { 

printf("you are not eligible for vote");

 }

  • this  condition is use  false (ie. age < 18) this block run.
  • It print the message “you are not eligible for vote”


 Program Output 

enter your age :- 18 
you are eligible to vote 

Related Post :-

type of css

php syntax

c program to check number prime or not

No comments:

Post a Comment