simple program

i just try to make a simple program that is asking for an integer and than is analyzing it and returns 1 if is true and 2 if is false. I've been thinking about 10 minutes already but I have no idea which is that simple logical expression to determine if the number is even or odd.
So any idea?
Thanks
Use the modulo operator ( % ), it returns the remainder of a division
x % y = remainder of x / y
10 minutes? Wow. You must be worn out ;o)

You can tell if a number is even or odd like this:
1
2
3
4
bool is_even(int num)
{
    return num % 2 == 0;
}

Here the % operator gives us the remainder after a division. When you divide by 2 an even number has zero remainder.
Last edited on
Thank you very much you have no idea how released I am
Topic archived. No new replies allowed.