aboutsummaryrefslogtreecommitdiffstats
path: root/isOddBetter.c
blob: 7788b4a05346251b40d803cf7ca96fd77a227b34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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;
}