Modulo ๐Ÿ”ข#

Operators#

Operators in C are symbols that tell the computer to perform a specific operation on some inputs. The inputs of an operator are called the operands.

Operators are taken primarily from math and logic. Hereโ€™s a list of the math operators in C.

Name

Symbol

Description

Example

Modulo

%

Gets the remainder from dividing the first number by the second number

50 % 10

Modulo#

There is a special โ€œremainderโ€ operator called the modulo operator. It can be used to find the remainder after two integers.

Ex.

4 % 2 = 0        // 4 / 2 = 2 remainder 0
3 % 2 = 1        // 3 / 2 = 1 remainder 1

10 % 3 = 1        // 10 / 3 = 2 remainder 1
11 % 3 = 2        // 11 / 3 = 2 remainder 2

Tasks ๐ŸŽฏ#

What does the modulo operator do?

Solution โœ…

The modulo operator gets the remainder from dividng the first number by the second number

What does the experssion 3 % 2 evaluate to?

Solution โœ…

7 % 2 = 1, because 7 divided by 2 is 2 with a remainder of 1.