int main()
{
int n;
//mask having least significant bit 1 and other bits are 0
int msk=0x1;
//Accept any number
printf("Enter a number:\n");
scanf("%d",&n);
//A number will be odd if its least significant bit
//i.e the right most bit is 1
//A number will be even if its least significant bit is 0
if((n & msk) ==0)
{
printf("Number is even\n");
}
else
{
printf("Number is odd");
}
}
0 comments: