+ 1
Modulus %
Hi. I'm beginer. i'm not understand for function Operator Aritmathic Modulus %.
3 Réponses
+ 3
% gives you the remainder of the euclidian division.
For example:
42%9 is 6, because 42 is 9*4 + 6 (and 0 <= 6 < 9).
x%y is 0 if x is a multiple of y.
x%2 is 0 if x is even and 1 if x is odd.
x%10 gives you the last digit of x.
x%100 gives you the last two digits.
etc.
@Andreas: in C#, 10/3 is actually 3. When both operands are integers, / does an euclidian division. You must have confused with javascript or python.
+ 1
when you divide number like 2/9 so it comes 1 as reminder that reminder represent %
0
Please use the search function.
This is about the fifth time I copied this from my other answers.
The % stands for modulo.
It's the remainder of a division.
First we divide our numbers 10/3. This gives us 3.3333333... Now this was from dividing. If we add modulo, 10%3 we get 1.
What we want is an interger from our division. 9/3 gives 3, 9%3 = 0.
10-9 = 1. 10%3 = 1.
10/3 does not work to get an interger, but 9/3 does. So
10-9 = 1
10%3 =1
Hopefully this explained what you wanted.