What is Modulo operation?

By : Milon
On : 11:36 PM

In computing, the modulo operation finds the remainder of division of one number by another (sometimes called modulus).

Given two positive numbers, a (the dividend) and n (the divisor), a modulo n (abbreviated as a mod n) is the remainder of the division of a by n .

For instance, the expression "5 mod 2" would evaluate to 1 because 5 divided by 2 leaves a quotient of 2 and a remainder of 1.

While "9 mod 3" would evaluate to 0 because the division of 9 by 3, has a quotient of 3 and leaves a remainder of 0; there is nothing to subtract from 9 after multiplying 3 times 3.

Modulus operator in c

The following example of modulo operation will explain itself better, For example you are given some hours, Let’s consider 772 hours and you are told to find out the extra days which do not make a day. Then you will do it by the following arithmetic division

So there are 32 days and 4 hour. Now you find your result 4(The extra days which do not make a day) But in programming we can do by just one command “772 mod 24” which evaluates 4.

See a program to find out the odd-even number with modulus operator