Oct 28, 2004 #1 mattias1975 Programmer Joined Jul 26, 2004 Messages 36 Location SE Is there any function in c that decides if a number is devidable with 2 or not?
Oct 28, 2004 1 #2 ArkM IS-IT--Management Joined Oct 21, 2002 Messages 1,819 Location RU 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)... Upvote 0 Downvote
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)...