what is modulus & How work it ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

what is modulus & How work it ?

i want to how to do work it ? help me anyone....

2nd Nov 2016, 2:35 PM
Rejon
Rejon - avatar
7 Answers
+ 8
Modulus is basically what you use to get the remainder of a number divided into another. So lets say we have 5÷2. How many times does 2 go into 5? Twice. If it only goes in twice. Then the remainder will be 1. So if you do 5%2 then it will equal 1. If you dont understand still, just reply. Glad to help :)
2nd Nov 2016, 3:08 PM
Jonah Berry
Jonah Berry - avatar
+ 7
Remainder is basic Math logics See this example, you must have done that in school 5 -------- 4 | 22 | -20 -------- 2 If you divide 22 by 4 & you get remainder 2 While in programming we use (%) sign for remainder 22 % 4 = 2 (To get remainder )
3rd Nov 2016, 6:35 AM
Waqas Asghar Bhalli
Waqas Asghar Bhalli - avatar
+ 3
In simple terms, it is a mathematical operation that returns the remainder of the division of two numbers.. Eg 12 / 5 is 2 with a 2 left over, so 12 % 5 is simply 2.. It is useful in cases where you want to test for divisibility. Eg a % b will return 0 if a is exactly divisible by b, n % 2 will return 0 if n is even, and so on.. I've personally used it in timing calculations. For example, if you have time in seconds, and you wish to convert to mm:ss ss = t % 60 mm = ((t - ss) / 60) % 60 Trust me, as you go deeper into programming, you will find more uses for the modulo operator..
3rd Nov 2016, 7:24 PM
Victor Durojaiye
Victor Durojaiye - avatar
+ 3
38 / 5 = 7 5 * 7 = 35 38 - 35 = 3
29th Nov 2016, 1:41 AM
Syed NomanulHasan
Syed NomanulHasan - avatar
+ 1
Modulus (%) is the result of a division. Example, when you divide 38 by 5 (i.e. 38/5) you get 7.6. Then multiply 7 by 5 you get 35, right? Subtract 35 from 38 then you get 3. Therefore, the 38%5 = 3. ☺
8th Dec 2016, 3:54 PM
Varnum Vorld
+ 1
you can just simply call modulus:remnant of division e.g 5 divided by 2 = 2 remainder 1 therefore --- 5 modulus 2 (5 % 2) = 1 simple isn't it
28th Dec 2016, 10:35 PM
Idowu Shogbon
Idowu Shogbon - avatar
+ 1
yep
7th Feb 2017, 5:09 AM
Bobby Todorov
Bobby Todorov - avatar