Write a program to check wheather number is Even or Odd :-


//Program to Check Even or Odd
		
#include<stdio.h>
#include<conio.h>
void find(int n);
main()
{

int num;
printf("Enter any number:");
scanf("%d",&num);
find(num);
}
void find(int n)

//True if the number is perfectly divisible by 2
{
if(n%2==0)
printf("Number is Even");
else
printf("Number is Odd");

getch();
}

Output:


Enter any number:1258
Number is Even

			

Working:-

1. In the program, integer entered by the user is stored in variable number.
2. Then, whether the number is perfectly divisible by 2 or not is check.
3. If the number is perfectly divisible by 2, test expression number%2 == 0 evaluates to 1 (true) and the number is even.
4. However, if the test expression evaluates to 0 (false), the number is odd.

Previous Next