What is modulo | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is modulo

%

10th May 2021, 4:57 PM
Khadidja Soltana
Khadidja Soltana - avatar
9 Answers
+ 2
Helps in taking out the remainder in division
10th May 2021, 5:04 PM
Atul [Inactive]
+ 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".
10th May 2021, 5:27 PM
sarada lakshmi
sarada lakshmi - avatar
+ 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.
10th May 2021, 5:28 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Hi! you will come across its use in 31 lessons -> project Fizz Buzz
10th May 2021, 5:30 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 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 )
11th May 2021, 5:12 AM
Godes Piee
Godes Piee - avatar
+ 1
Keep in mind in theory the reminder should always be positive but in programming languages it's not always the case
11th May 2021, 5:13 AM
Godes Piee
Godes Piee - avatar
+ 1
what is the result? do you know why 2%7=2?
11th May 2021, 9:34 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Yaroslav Vernigora 2%7=2. Because 7)2(0 0 --- 2
12th May 2021, 4:32 AM
Atul [Inactive]
0
Why 2%7=2?
11th May 2021, 9:09 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar