English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

5 answers

you can use a simple function of your own:

void tell(int x)
{
if(x%2==0)
cout<<"even";
else
cout<<"odd";
}

2007-02-03 15:17:17 · answer #1 · answered by wretrovian 1 · 3 1

The % is a modulus operator. it divides by whatever number you put behind it and returns the remainder. if the remainder is = to 0 then it is divisible. Hence %2==0 then, else

2007-02-04 01:43:28 · answer #2 · answered by Anonymous · 0 0

Even simpler - just use the & operator. You can make a macro:

#define ODD(XX) ((XX) & 1)

2007-02-03 23:32:25 · answer #3 · answered by sofarsogood 5 · 0 0

another way is:

int number;

if ((number & 0x1) == 0x0)
//even
else
//odd

2007-02-04 09:03:08 · answer #4 · answered by justme 7 · 0 0

yes. see above

2007-02-03 23:21:52 · answer #5 · answered by Keith B 4 · 0 0

fedest.com, questions and answers