0
What does %= do?
4 Réponses
+ 1
a %= 5
its the same as
a = a%5
+ 1
its called the modulus operator. basically what you are saying is you want to get the remainder of the after you divider a number with another ..
so x%=y is shortened version of x = x%y
you can have +=, -=, /=
0
I couldn't understand your answer can you explain it for me by onther example
0
Consider this:
a = 9;
b = 3;
a = a % b will store in the variable a the value 0, because a divided to b (3) has a reminder of 0.
a %= b is the same as a = a % b.
If b = 2,
a = a % b will store in the variable a the value 1, because a divided to b (2) has a reminder of 1.