Program to test whether a given number is even or odd using bitwise & operator in C Programming Language

write a Program to test whether a given number is even or odd using bitwise & operator in C Programming  

Program to test whether a given number is even or odd using bitwise & operator in C Programming Language



#include<stdio.h>
main()
{
int n;clrscr();
printf(“n Enter a number :”);
scanf(“%d”,&n);
if(n&1) /*ANDing with LSB*/printf(“n Number is odd “);
else
printf(“n Number is Even “);
return;
}


Output:
Enter a number :8
Number is Even
Enter a number :9
Number is odd

Post a Comment