Thursday, September 29, 2011

To check number is odd or even without using OPERATOR( C++)

Hint: When we do conversion from decimal to binary then you have noticed that last digit of binary number is '0' if number is even ELSE '1'.
Using same logic we will solve this program.

#include "iostream.h"
#include "conio.h"
void main()
{
int number, last_digit;
cout<<"Enter the Number"; cin>>number;

last_digit=number & 1; //Give the last digit of Binary number

if(last_digit==0)
cout<<"Number is EVEN";

else
cout<<"Number is ODD";
}