+ 1
I don't believe I understand the modulus operator very well.
6 odpowiedzi
+ 12
@sandra pérez The modulus operator is very different from division. it does divide, but that number is discarded, whatever is left is printed. in the example of 25%7 we get this;
25/7 does not give a whole number, 21/7 is the closest since we cant increase the starting value of 25. this results in 3, but is discarded. 25-21 is all that matters here, and the answer to that is 4.
this can be used to calculate for example; the number of leftover days in a year when you divide the days in a year (365) by the number of weeks in a year (52). 365%52 becomes 364/52 to make the result a whole number. 365-364=1, in this case 1 is printed. Hope this helps:)
+ 8
In short, it calculate the remainder in a division.
+ 2
For any positive real x and y where x > y, the modulus operator is defined as follows:
x % y = x - (y * floor(x / y))
Where floor(n) is the largest integer less than or equal to argument n.
0
It is used to find the remainder of a division operation. For example 9 % 4 = 1, because the closest 4 can get to 9 is 4 * 2 which is 8, with a remainder of 1.
0
just you remember one thing...division operator(/) gives you quotient and the modulus operator(%) gives you the remainder...that's it..
0
remainder is the value