top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

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

0 votes
107 views
How to find a no is even or odd without using % operator or without using loop?
posted Sep 7, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

5 Answers

+1 vote
 
Best answer

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");
}
answer Dec 2, 2014 by Bheemappa G
+5 votes

Try something like (assume a is your integer)

if (a & 1)
 printf("a is odd number");
else
 printf("a is even number");
answer Sep 7, 2014 by Salil Agrawal
+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
answer Jul 3, 2017 by Ajay Kumar
0 votes
main()
{
 int n,a;
 cin>>n;
 a=n&1;
 if(a==1)
  cout<<"odd";
 else
  cout<<"even";
}
answer Sep 7, 2014 by anonymous
0 votes
#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();


}
answer Dec 2, 2014 by Shivaranjini
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...