PDA

View Full Version : Checking numbers for multiples




HarryWorksInc
Aug 7, 2010, 06:21 PM
Is there anyway to check for multiples of a certain number? I would do something like:if (num==0) {
//code
} else if (num==5) {
//code
} else if (num==10) {
//code
}
But these numbers will go into the thousands so it would be very complicated to do it that way.

Thanks



chown33
Aug 7, 2010, 06:32 PM
Look up the modulo operator in C, represented by the % symbol.
if ( (num % 5) == 0 ) ...

HarryWorksInc
Aug 8, 2010, 11:42 AM
Thanks that works.