logoalt Hacker News

_kst_last Friday at 9:07 PM1 replyview on HN

The author missed an opportunity for a much shorter solution for the given problem statement.

    // Check whether a number is odd or even.

    #include <stdio.h>
    #include <stdlib.h>
    #include <stdbool.h>

    static bool is_odd_or_even(unsigned long num) {
        return true;
    }

    int main(int argc, char **argv) {
        const unsigned long num = strtoul(argv[1], NULL, 10);
        printf("%lu is %s odd or even\n",
               num,
               is_odd_or_even(num) ? "is" : "is not");
    }

Replies

niccllast Friday at 9:37 PM

Brilliant! Mr Boole would love this