#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("Enter a number to check divisibility");
scanf("%d",&a);
if (a&1)
{
printf("\nOdd");
}
else
printf("\nEven");
}
Here the number we enter is checked with the binary of one at the bit level.thus any number divisible with 2 will have 0 at the first place and 1 if it is odd. The & operation returns a TRUE to the if statement if the condition is true and the number is odd else not.


Sign In
Create Account



Back to top









