+ 1

# I don't understand modulus(%) operator..

3 Answers

+ 4

Modulus operator is another word for remainder. (%)
10 % 3 : how?
-> 10/3 = 3, with remainder of 1
so, 10 % 3 = 1

+ 1

Check the following examples
1) 28 % 7
as 7 * 4 = 28 = 28 - 28 = 0
answer is zero
2) 28 % 3
as 3 * 9 = 27 = 28 -27 = 1
answer is 1
3) 5 % 2
2 * 2 = 4 = 5 - 4 = 1
Answer is 1
4) 8 % 2
2 * 4 = 8 = 8 - 8 =0
Answer is 0
5)9%8
8 * 1 = 8 = 9 - 8 = 1
Answer is 1

0

% is modulus operator
It is used to get remainder
If we divide 24 by 7 then remainder is 3 not 4
7 * 3 = 21
24 - 21 = 3