How is the modulo operator used to determine if divisible by a number?


#1

Question

For this exercise, the modulo operator is used to determine if the number is divisible by 10. Why does a 0 result mean that the number is divisible?

Answer

The modulo operator returns the remainder portion of a division operation. If one number is evenly divisible by another number, there will be no remainder. So, if the modulo operator returns a 0, then it means that the number is evenly divisible by 10.