Modulus/Modulo?

This is a discussion on Modulus/Modulo? within the C++ Programming forums, part of the General Programming Boards category; Exactly what is modulus/modulo? Every single one of my C++ books mentions it but doesn't really say what it is!!! ...

  1. #1
    Shadow12345
    Guest

    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

  2. #2
    $null
    Guest
    modulus of a number gives you the remainder of the division eg:

    16/10=1
    16%10=6

    25/10=2
    25%10=5

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    203
    maybe easier to understand % as the remainder of int division
    with integers 23/5 is 4
    23%5 will produce 3

  4. #4
    ...
    ... is offline
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    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.
    I came up with a cool phrase to put down here, but i forgot it...

  5. #5
    ...
    ... is offline
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    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...


    I came up with a cool phrase to put down here, but i forgot it...

  6. #6
    Shadow12345
    Guest

    Oh, derr

    Oh okay, if the chemicals in my brain were allowing for my thoughts to work I could have figured that out
    Thanks you guys!

  7. #7
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    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.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21