[ create a new paste ] login | about

Link: http://codepad.org/lbha2sv2    [ raw code | output | fork ]

C, pasted on Sep 3:
#include <stdio.h>

int is_odd(unsigned n);
int is_even(unsigned n);

int is_even(unsigned n)
{
    return n == 0 ? 0 : is_odd(n-1);
}

int is_odd(unsigned n)
{
    return n == 0 ? 0 : (n == 1 ? 1 : is_even(n-1));
}

int main(void)
{
    const unsigned num = 33;

    printf("%u is %s\n", num, is_even(num) ? "even" : "odd");

    return 0;
}


Output:
1
33 is odd


Create a new paste based on this one


Comments: