How to detect if a number is even - eviltoast
  • lowleveldata@programming.dev
    link
    fedilink
    arrow-up
    3
    ·
    edit-2
    1 year ago

    Good solution! I think you should show the last 3 lines that makes it work tho. FIFY:

    private bool IsEven(int number){
        if (number == 1) return false;
        else if (number == 2) return true;
        else if (number == 0) return true;
        else if (number == -1) return false;
        else return !IsEven(abs(number) - 1);
    }