# Thread: Odd / Even numbers

1. ## Odd / Even numbers

I saw this on the forum about 3 weeks ago but can't seem to find it.

All I want to do is differentiate between an odd and even integer entered by the user:

Code:
```int main ()
{
int number;

cout << "Number: ";
cin >> number;

// test etc

return 0;
}```

2. You can use a modulus of 2 to check for a remainder, or do a bit-wise AND with 1.

gg

3. Thank you! Maths was never my strong point....

4. Maybe you shouldn't be programming then.. programming involves a lot of math

in my school my Math teacher had a chart thing it had over 100 professions on it and lot of math things on the side, and if the profession required the math thing it had a dot..

only two that had the whole columns full were Programmer and physicist

5. Oh don't worry man I've been programming for 4 years and 5 months (not sure about the days ) and any maths problems I have I find enjoyable to solve by picking up a good maths book.

For some reason I find it hard to learn maths, not sure why. Programming and computing are my passions

6. Math Lesson of the day

what the cubed root of 512, no cheats!!!!

7. 128

8. close its 8

8 * 8 * 8 = 512

9. Oh no, my 3rd U grade in Maths this year.

10. Code:
```if(number % 2) {  /* number is odd */

}
else {  /* number is even */

}```

11. Cool programmers simply write:

Code:
```bool is_odd(unsigned int x);
bool is_even(unsigned int x);

bool is_odd(unsigned int x)
{
if (x) return is_even(x - 1);
return false;
}

bool is_even(unsigned int x)
{
if (x) return is_odd(x - 1);
return true;
}```
;-)

12. Yeah really cool. Superfast especially for big numbers. I hope cool was a synonym for dumb.

13. >programming involves a lot of math
It depends on the field. In my experience, the only math that is required is basic arithmetic. Higher math helps, but not for everyday programming.