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

1. ## 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

2. if(num%2 == 1) it's odd

3. 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

4. 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

5. Thanks people! The answer was simple but I just couldn't see it because I was thinking about it too much.

Colin

Popular pages Recent additions