0

% I dont understand what this arithmetic operator is doing

14th Jun 2016, 4:59 PM
Teofil Shterev
Teofil Shterev - avatar
3 Answers
+ 3
% modulus operator yields the remainder after division. For example, 1%2 gives 1 or 10%3 gives 1 the remainder or 12%24 givea 12 because it is the remainder and 12 cannot be divided by 24 without a remainder
14th Jun 2016, 8:01 PM
Sardor
Sardor - avatar
0
It's giving the remainder dear!
16th Jun 2016, 8:37 PM
Utpal Kumar
Utpal Kumar - avatar
0
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:)
20th Jun 2016, 1:16 AM
Utpal Kumar
Utpal Kumar - avatar