0
I don't understan this operator %= why the result is 3 for this expression? int x = 15; int y = 6; Console.WritLine(x %= y);//output 3
9 ответов
+ 8
x %=y is equivalent to x=x%y.
% is called modulus. it will give us remainder of division of two numbers.
i.e. x=15%6
x=3.
+ 3
it stands for the remainder we get after division..!
when we divide 15 by 6..it will give us 3 as remainder as 6*2=12 and 15-12=3!!
hope u understand by this.
+ 2
the fact is that the modulus operator shows the reminder of an operation that why 15%6 = 3 that's mean
15/6 = 2 and the reminder is 3 and it shows 3 as the result and not 2 . I hope you understand .
+ 1
basically its remainder of division of two nos.
0
What Jaimin said, 3 is closer to 15 and 6 division wise.
0
6 goes into 15 two times (12) with a remainder of 3, or 15 modulus 6 (x % y) = 3
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:)
0
int x=17;
int y=6;
Console.WriteLine(x%=y);
Here x %= y means 17/6 = 2 and rest of division 5. % is a Modulus and %= means the rest of division. So the result is 5.
- 1
if we divide 15 by 6 = 12 then you take the remainder 15 - 12 = 3 and that will be your answer