C Programming Reference
 
C Programming Reference >> C  Programming Reference Question Bank >>

19/07/07 - 656 Views - Ratings :   0 of 5 /  Votes

Level - Beginner
      

Question -

Write a program to find and print the given number is odd or even, Using only one printf (output) statement, no conditional Statement and no logical,relational and arithmatic operators.


Answer -
#include <stdio.h>
main()
{
int x; scanf ("%d",&x);
printf ("%d",x&1);
}
Explanation -

This an easy to understand code. What we have done here is use the bitwise AND operator and use it to bitwise AND the being evaluated number with 1.

The code will print 1 when number is odd and 0 when number is even, which do task in the question quite efficiently.

Reader Comments -

Author Comments
Add Comments 


Name :    
Reply :   


Rating :

Code :
Code

 

 
© 2006 cencyclopedia.com