Write a function that checks whether a number is even or not using bit manipulation.
Difficulty level
This exercise is mostly suitable for students
#include<stdio.h>
#include<conio.h>
int isEven(int nb)
{
return !(nb & 1);
}
void main()
{
int a;
printf("Enter an integer: ");
scanf("%d", &a);
if (isEven(a))
printf("%d is even.\n",a);
else
printf("%d is odd.\n", a);
getch();
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Asymptotic Analysis 19