+ 5
what is modulus & How work it ?
i want to how to do work it ? help me anyone....
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 :)
+ 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 )
+ 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..
+ 3
38 / 5 = 7
5 * 7 = 35
38 - 35 = 3
+ 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. âș
+ 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
+ 1
yep