+1

Don't Understand Quiz Answer

This question appeared in the quiz. I paid points to unlock the answer and it displayed "3". I didn't understand why and tried to get a hint to help me but it didn't give me a hint and deducted one of my points. I repeated the hint request thinking maybe I clicked the wrong button and same result (and another point lost!) Meh! Why is the answer 3 here? if x=15, wouldn't the code output x (i.e., 15) per the WriteLine statement? And if modulus is at play, how could 3 be the answer? 15 % = 6 can't even be solved because 6 can't be the remainder with 15 being the starting point. Is the answer right in front of my face? And how do I get my 2 points back since I never got the hints? Thanks! What is the output of this code? int x = 15; int y = 6; x %= y; Console.WriteLine(x);

in

1/30/2020 8:17:17 PM

Lisa

3 Answers

New Answer

+2

Lisa really it is easier than you think as the % is asking for the remainder 6 goes into 15 twice leaving the remainder of 3 ... hope that helps. Thanks

+2

x %= y is the same as x = x % y

0

% operator return reminder. x%=y x=x%y=15%6=3 Since 15/6=2 / return quotient.