Ategon@programming.dev to Programmer Humor@programming.dev · 1 year agoHow to detect if a number is evenprogramming.devexternal-linkmessage-square5fedilinkarrow-up111arrow-down12
arrow-up19arrow-down1external-linkHow to detect if a number is evenprogramming.devAtegon@programming.dev to Programmer Humor@programming.dev · 1 year agomessage-square5fedilink
minus-squarelowleveldata@programming.devlinkfedilinkarrow-up1·edit-21 year agoGood 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); }
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); }