Monday, 13 March 2017

C Program to Check whether a Number is Even or Odd without using Arithmetic Operators

We can check whether a number is even or odd without using arithmetic operators in C to do this let us first consider the binary of some of numbers

1:00000001
2:00000010
3:00000011
4:00000100
5:00000101
6:00000110
There is a catch here, we can see that each of the odd number has the rightmost(LSB) bit as '1'. We can use this information and find out whether a number is even or odd. If we apply 'bitwise &' operator on number and 00000001, it will result in 00000001 if the number is odd.

Here is the C code :

#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("***************Even or Odd without Arithmetic Operators****************\n");
printf("Enter a Number");
scanf("%d",&n);
if(n&1==1)
printf("It is Odd");
else
printf("It is even");
getch();
}

Hope you like the solution.




Best program to find  whether a Number is Even or Odd without using Arithmetic Operators 
Best algorithm to find  whether a Number is Even or Odd without using Arithmetic Operators 
Best algorithm to check  whether a Number is Even or Odd without using Arithmetic Operators 
Best program to check  whether a Number is Even or Odd without using Arithmetic Operators
Best C program to find  whether a Number is Even or Odd without using Arithmetic Operators 
Best C program to check  whether a Number is Even or Odd without using Arithmetic Operators
C program to check  whether a Number is Even or Odd without using Arithmetic Operators 

No comments:

Post a Comment