# How to make program be able to tell whether a number is odd or even

• 03-08-2002
Niloc1
How to make program be able to tell whether a number is odd or even
I'm writing a program in C and have encountered an obstacle. Here's my pseudocode:

prompt for 1st number
while EOF is not reached

print the number
if number is even

print"This is an even number"

else

print"This is an odd number"

read the next number

I've got the basics down, but I can't figure out how to make the program figure out whether a number is odd or even. Any help would be appreciated.

Colin
• 03-08-2002
Govtcheez
if(num%2 == 1) it's odd
• 03-09-2002
iain
the % is the modulus operator and returns wether or not there is a remainder after the number has been divided by 2 (an even number) - if there is a remainder it is odd
• 03-09-2002
klausi
A faster method than the one with modulo is:
Code:

```if (number&1) puts("the number is odd");   else puts("the number is even");```
klausi
• 03-09-2002
Niloc1
Thanks people! The answer was simple but I just couldn't see it because I was thinking about it too much.

Colin