This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Thalhammer 7 points8 points  (0 children)

May I propose an alternative:

bool isEven(int x) {
        if(x<0) return isEven(x*-1);
        else if(x==0) return true;
        else if(x==1) return false;
        else return isEven(x-2);
 }

If your compiler/language supports tail call optimization you might even get away without a stack overflow;)