mmoodduulluuss -- Definition

_M_o_d_u_l_u_s  is  the  operation  that  returns  the  remainder  of  a  division
operation.  For  example, 12 modulus  four equals zero, because  when 12 is
divided by four it leaves no remainder.  The term ``modulo'' also refers to
the product  of a modulus  operation; in the  above example, the  modulo is
zero.  In  C, the modulus operation  is indicated with a  percent sign `%';
therefore, 12 modulus 4 is written 1122%44.

The modulus operation often is used to trim numbers to a preset range.  For
example, if you wanted to create a list of single-digit random numbers, you
would use the command:

    rand()%10

This is demonstrated by the following example.

_E_x_a_m_p_l_e
This example prints a list  of 20 single-digit random numbers.  The random-
number table is seeded with a portion of the current system time.

#include <stdio.h>
#include <stdlib.h>

main()
{
    long nowhere;   /* place to put unused data */
    int counter;

    srand((int)time(&nowhere));
    for (counter = 0; counter <20; counter++)
        printf("%d\n", rand()%10);
}

_S_e_e _A_l_s_o
ooppeerraattoorr, PPrrooggrraammmmiinngg CCOOHHEERREENNTT

_N_o_t_e_s
The  implementation of  C defines  how a modulus  operator behaves  when it
operates upon numbers with different signs.  On the i8086,

    10 % -4

yields -2.  This is not mathematical modulus, which is +2.
