.TH modulus "" "" Definition
.PC
.PP
.I Modulus
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
\*(QLmodulo\*(QR 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 \*(Ql%\*(Qr; therefore,
12 modulus 4 is written \fB12%4\fR.
.PP
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:
.DM
	rand()%10
.DE
.PP
This is demonstrated by the following example.
.SH Example
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.
.DM
#include <stdio.h>
#include <stdlib.h>
.DE
.DM
main()
{
	long nowhere;	/* place to put unused data */
	int counter;
.DE
.DM
	srand((int)time(&nowhere));
	for (counter = 0; counter <20; counter++)
		printf("%d\en", rand()%10);
}
.DE
.SH "See Also"
.Xr "operator," operator
.Xr "Programming COHERENT" programmi
.SH Notes
The implementation of C defines how a modulus operator behaves
when it operates upon numbers with different signs.
On the i8086,
.DM
	10 % -4
.DE
.PP
yields \-2.
This is not mathematical modulus, which is +2.
