how does the modulus work? still dont get it | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

how does the modulus work? still dont get it

25th Oct 2016, 1:25 AM
silvana suyasa
silvana suyasa - avatar
6 Réponses
+ 1
let's first know what's division here. it will clear the doubt about modulus operation. take an example: 5/3 . here 5 --> dividend, 3 --> divisor and / --> division operator. as we know when we devide one number by another one result will have two entities. one is 'quotient' and the other one is 'remainder'. when we devide 5 by 3 , it yields 1 as 'quotient' and 2 as 'remainder'. In computer programming languages such as c, c++ and Java etc. / operator used to output quotient. and % operator used to output remainder. Hence, 5/3=1 and 5%3=2.
25th Oct 2016, 4:37 AM
Rakesh S G
+ 1
See my "% Modulus explained" code to understand in a way, you may have learnt at school https://code.sololearn.com/c2fRl6x893E7/?ref=app
31st Dec 2016, 12:46 PM
Vishal++
Vishal++ - avatar
0
Here's a quick rundown of how modulus works. Take the following as the equation your using: 11 % 2; Here, we are basically doing do 11 / 2 however, 2 cannot go into 11 perfectly. So, we divide 11 as much as we can without having a fraction or decimal in the end. So, 2 can go into 11 five times. 2 * 5 = 10 Now you take 11 and subtract it by 10: 11 - 10 = 1 Here you have your remainder. Now, modulus simplifies this in that it crams all of this work into one sign. TL;DR Version: Modulus shortens the work needed to get the remainder from integer division. I hope this helps!
25th Oct 2016, 1:52 AM
Martin Flores
Martin Flores - avatar
0
thank u so much!
25th Oct 2016, 2:46 AM
silvana suyasa
silvana suyasa - avatar
0
No problem!
25th Oct 2016, 2:50 AM
Martin Flores
Martin Flores - avatar
0
thanks
28th Oct 2016, 5:29 PM
Waheed Zaman
Waheed Zaman - avatar