Can someone describe what the modulus operator is, I don't understand it. | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

Can someone describe what the modulus operator is, I don't understand it.

none

16th May 2017, 12:37 AM
Chris Ballard
Chris Ballard - avatar
6 Réponses
+ 14
As long as you know what division is... you know what modulus (modulo reduction) is. Think of it like this... 11 divided by 5 is 2, with a remainder of 1. (5 * 2 + 1 = 11) or.. 13 divided by 7 is 1, with a remainder of 6. (7 * 1 + 6 = 13) basically, just divide the numbers wherever you see the modulus operator, and the remainder will be the answer.
16th May 2017, 12:52 AM
Fox
Fox - avatar
+ 11
5 divided by 2 results in 2 with remainder of 1. You can read 5 % 2 as five modulus 2, or the remainder when 5 is divided by two. Hence, 5 modulus 2 is 1. More examples: 5%3 = 2 11%5 = 1 12%11 = 1 1%2 = 1
16th May 2017, 12:57 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
Modulus cannot be greater than the divisor
16th May 2017, 1:01 AM
Siddharth Saraf
+ 1
Is what's left on a division, also called reminder For example 15/15 = 1 (Modulo 0) Another example is 5/3 = 1.6 (modulo 2) 6/3 = 2 (Modulo= 0)
16th May 2017, 1:01 AM
Juan Monge
Juan Monge - avatar
+ 1
Thank you. Makes so much sense now. I got caught up with the percent sign.
16th May 2017, 2:02 AM
Chris Ballard
Chris Ballard - avatar
0
Modulo is the remainder.
16th May 2017, 2:21 AM
Sabrina Aviles