Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Decide if a number is devidable with 2 1

Status
Not open for further replies.

mattias1975

Programmer
Jul 26, 2004
36
SE
Is there any function in c that decides if a number is devidable with 2 or not?
 
A function? What for?
Code:
int n;

if (n&1) /* if is odd... */
...
if (n&1 == 0) /* if is even... */
... /* or */
if (n%2 == 0) /* for purists only... */
...
Of course, you may define macros if you wish:
Code:
#define iseven(n) ((n)%2==0)
...
if (iseven(n))
...
These examples are for integral types (char, int, long)...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top