Recognizing when to use the mod operator

Posted by Will on Stack Overflow See other posts from Stack Overflow or by Will
Published on 2010-04-09T16:54:38Z Indexed on 2010/04/09 17:03 UTC
Read the original article Hit count: 485

Filed under:
|
|
|
|

I have a quick question about the mod operator. I know what it does; it calculates the remainder of a division. My question is, how can I identify a situation where I would need to use the mod operator? I know I can use the mod operator to see whether a number is even or odd and prime or composite, but that's about it. I don't often think in terms of remainders. I'm sure the mod operator is useful and I would like to learn to take advantage of it. I just have problems identifying where the mod operator is applicable. In various programming situations, it is difficult for me to see a problem and realize "hey! the remainder of division would work here!" Any tips or strategies?

Thanks

© Stack Overflow or respective owner

Related posts about programming

Related posts about mod