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 |
|
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.