What does the modulus operator do? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What does the modulus operator do?

english is not my native language, i understand almost everything, but not the modulus. Help!!!

3rd Jul 2017, 2:58 PM
Vinicius Martiniano
Vinicius Martiniano - avatar
7 Answers
+ 1
its like 12%5=2 because 5*2= 10, then it will rest 2, and this is the answer, 12%5=2 right?!
3rd Jul 2017, 3:20 PM
Vinicius Martiniano
Vinicius Martiniano - avatar
+ 1
thanks, you just teach me a new operator :P
3rd Jul 2017, 3:25 PM
Vinicius Martiniano
Vinicius Martiniano - avatar
0
It's a strange operator : It returns the rest of a division : 12%5=2 // weird uh ? 2*5=10 12-10=2 another exemple : 5%2=1 2*2=4 5-4=1 Ask if you don't understand !
3rd Jul 2017, 3:08 PM
Jojo
0
why the another example, it is 2*2 and not 2*1?
3rd Jul 2017, 3:11 PM
Vinicius Martiniano
Vinicius Martiniano - avatar
0
5%2 --> 5/2 how much 2 in 5, two because 2*2=4 4<5and 2*3=6. 6>5 2 is the 'quotient' (sorry I'm french X) ) Then to find the rest : 5-4=1 I don't know if it's ok, it's difficult to explain If you still don't understand, I can try a code
3rd Jul 2017, 3:17 PM
Jojo
0
ohhh now i completely understand, thanks a lot ^-^
3rd Jul 2017, 3:18 PM
Vinicius Martiniano
Vinicius Martiniano - avatar
0
Exactly !!
3rd Jul 2017, 3:24 PM
Jojo