# Odd / Even numbers

• 07-22-2005
cboard_member
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; }```
• 07-22-2005
Codeplug
You can use a modulus of 2 to check for a remainder, or do a bit-wise AND with 1.

gg
• 07-22-2005
cboard_member
Thank you! Maths was never my strong point.... :(
• 07-22-2005
mrafcho001
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
• 07-22-2005
cboard_member
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 :)
• 07-22-2005
ILoveVectors
Math Lesson of the day

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

and only ahluka can answer.
• 07-22-2005
cboard_member
128 :p
• 07-22-2005
ILoveVectors
close its 8

8 * 8 * 8 = 512
• 07-22-2005
cboard_member
Oh no, my 3rd U grade in Maths this year.

*points gun to head*
• 07-22-2005
dwks
Code:

```if(number % 2) {  /* number is odd */ } else {  /* number is even */ }```
• 07-22-2005
Rashakil Fol
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; }```
;-)
• 07-22-2005
Stoned_Coder
Yeah really cool. Superfast especially for big numbers. I hope cool was a synonym for dumb.
• 07-23-2005
Prelude
>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.