# Modulus/Modulo?

• 03-13-2002
Modulus/Modulo?
Exactly what is modulus/modulo? Every single one of my C++ books mentions it but doesn't really say what it is!!! It is used as division when comparing two int values. For example

#include <iostream.h>

int main()
{
int one = 10;
int two = 5;

if(one % two == 0) <---//This is where the modulus thingy is used
cout << "The first number is evenly divisible by the second";
else
cout << "The second number is not evenly divisible by the

second";
return 0;
}

I asked my math teacher what it is, and she said that "We aren't going to be getting into that during this school year" ;
ok thanks
• 03-13-2002
\$null
modulus of a number gives you the remainder of the division eg:

16/10=1
16%10=6

25/10=2
25%10=5
• 03-13-2002
Syneris
maybe easier to understand % as the remainder of int division
with integers 23/5 is 4
23%5 will produce 3
• 03-13-2002
...
ah! a question i can answer!

modulus ( % ) is a very simple operation. basically:

a % b

will return the remainder of a divided by b. for example:

4 % 3

three goes into 4 once, with a 1 remainder, so it returns a 1

4 % 3 = 1

its as simple as that.
• 03-13-2002
...
argh, i spend all that time making that post, and then i hit the send button just in time to see that 2 people have already beat me to it...

:(
• 03-13-2002