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

15th Jun 2016, 5:53 PM
Tommaso
9 Answers
+ 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.
15th Jun 2016, 6:45 PM
BIPLAB BISWAS
BIPLAB BISWAS - avatar
+ 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.
16th Jun 2016, 11:10 AM
Mayank Rana
Mayank Rana - avatar
+ 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 .
15th Jun 2016, 9:49 PM
Aboubacar Traore
Aboubacar Traore - avatar
+ 1
basically its remainder of division of two nos.
15th Jun 2016, 6:16 PM
Jaimin Kachhadiya
Jaimin Kachhadiya - avatar
0
What Jaimin said, 3 is closer to 15 and 6 division wise.
15th Jun 2016, 9:07 PM
SaiyanWarrior15
SaiyanWarrior15 - avatar
0
6 goes into 15 two times (12) with a remainder of 3, or 15 modulus 6 (x % y) = 3
19th Jun 2016, 12:10 AM
Leon Tory Walker
Leon Tory Walker - 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
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.
13th Jul 2016, 2:34 PM
Md. Shariful Islam
Md. Shariful Islam - avatar
- 1
if we divide 15 by 6 = 12 then you take the remainder 15 - 12 = 3 and that will be your answer
16th Jun 2016, 3:44 PM
jared Mccallum