Ategon to Programmer [email protected] • 2 years agoHow to detect if a number is evenprogramming.devimagemessage-square20fedilinkarrow-up170arrow-down12
arrow-up168arrow-down1imageHow to detect if a number is evenprogramming.devAtegon to Programmer [email protected] • 2 years agomessage-square20fedilink
minus-square@[email protected]linkfedilink7•edit-22 years 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); }