0
What is modulo
%
9 Answers
+ 2
Helps in taking out the remainder in division
+ 1
results in remainder.
For ex :-
10) 50 (5
50
-----------
( 0 ) #remainder part
So, when you do print(50%10) the output will be "0".
+ 1
The operator of the remainder of the number %
(for example: 17 % 3 = 2)
1. Take the nearest number when divided by 3 would be zero. That's apparently 15
2. Subtract 15 from 17 and the result is your answer.
+ 1
Hi! you will come across its use in 31 lessons -> project Fizz Buzz
+ 1
So suppose you want to share 12 apples to 5 people fairly so imagine 5 boxes in front of you and start putting in each box 1 apple at a time so you put in the first box 1 apples in the second box 1 apple etc... and after the first round you put 5 apples and you have 7 left and you can notice that all boxes have the same amount of apples which is what we want now same method you have 7 apples >5 you do the same thing again and now you are left with 2 apples and you can notice that 2 <5 so you can't share it anymore with 5 people hence 2 will be left over so the notation is 12 mod(%) 5=2, so you successfully divided 12 fairly , each person / box got 2 apples ( remember 2 rounds and each round costs 5 apples and from 1 round each box gained 1 apple )
+ 1
Keep in mind in theory the reminder should always be positive but in programming languages it's not always the case
+ 1
what is the result? do you know why 2%7=2?
+ 1
Yaroslav Vernigora 2%7=2. Because
7)2(0
0
---
2
0
Why 2%7=2?