diff options
author | EliteTK <tomasz.kramkowski@gmail.com> | 2014-02-24 21:03:53 +0000 |
---|---|---|
committer | EliteTK <tomasz.kramkowski@gmail.com> | 2014-02-24 21:03:53 +0000 |
commit | be9d9aedb53e9b3211765f16bf4b90f5d31c1722 (patch) | |
tree | f9368e8a880abf9b9392d631da1e5a373c23dc7e /isOddBetter.c | |
parent | de4075f451a2d6e457dbf9dff714d166618c4495 (diff) | |
download | c-stuff-be9d9aedb53e9b3211765f16bf4b90f5d31c1722.tar.gz c-stuff-be9d9aedb53e9b3211765f16bf4b90f5d31c1722.tar.xz c-stuff-be9d9aedb53e9b3211765f16bf4b90f5d31c1722.zip |
Added all files
Diffstat (limited to 'isOddBetter.c')
-rw-r--r-- | isOddBetter.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/isOddBetter.c b/isOddBetter.c new file mode 100644 index 0000000..7788b4a --- /dev/null +++ b/isOddBetter.c @@ -0,0 +1,20 @@ +#include<stdio.h> + +_Bool isOdd( int ); + +int main ( int argc, char *argv[] ) { + if ( argc == 2 ) { + printf("%s\n", isOdd( atoi( argv[1] ) ) ? "true" : "false" ); + return 0; + } else { + printf("Usage: '%s <number>'\n", argv[0]); + return 1; + } +} + +_Bool isOdd( int n ) { + // Bitwise and with LSB to check if number is odd or even. + // LSB == 0 => even + // LSB == 1 => odd + return n & 1; +} |