-
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
-
modulus of a number gives you the remainder of the division eg:
16/10=1
16%10=6
25/10=2
25%10=5
-
maybe easier to understand % as the remainder of int division
with integers 23/5 is 4
23%5 will produce 3
-
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.
-
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...
:(
-
Oh, derr
Oh okay, if the chemicals in my brain were allowing for my thoughts to work I could have figured that out :D
Thanks you guys!
-
If you say congruent modulo this means that
a := b (mod n) if a-b is divisible by n.
It's what a math teacher would
think you mean.