# How to find a no is even or odd without using % operator or without using loop?

134 views
How to find a no is even or odd without using % operator or without using loop?
posted Sep 7, 2014

+1 vote

if LSB bit is set ,the given no is odd otherwise given no is even.

``````#include <stdio.h>
int num_odd_even(unsigned int num)
{
if(num & 1)
printf("Given no is odd\n");
else
printf("given no is even");
}
``````

Try something like (assume a is your integer)

``````if (a & 1)
printf("a is odd number");
else
printf("a is even number");
``````
+1 vote
``````#include<stdio.h>
void main()
{
int i,j;
printf("Enter a number:\t");
scanf("%d",&i);
j=i/2;
if(i==j*2)
printf("even");
else
printf("odd ");
}
``````

//-------------------------------------OR---------------------------------------

``````#include<stdio.h>
int main()
{
int x = 19;
(x & 1)? printf("Odd"): printf("Even");
return 0;
}
// Output: Odd
``````
``````main()
{
int n,a;
cin>>n;
a=n&1;
if(a==1)
cout<<"odd";
else
cout<<"even";
}
``````
answer Sep 7, 2014 by anonymous
``````#include<stdiio.h>

#include<conio.h>

void main()

{

int i,j;

clrscr();

printf("

Enter the number");

scanf("%d",&i);

j=i/2;

if(i==j)

printf("

Entered number is even");

else

printf("

Entered number is odd ");

getch();

}
``````