Don't Understand Quiz Answer | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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);

30th Jan 2020, 8:17 PM
Lisa
3 Answers
+ 3
x %= y is the same as x = x % y
30th Jan 2020, 8:21 PM
Paul
Paul - avatar
+ 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
30th Jan 2020, 8:20 PM
BroFar
BroFar - avatar
0
% operator return reminder. x%=y x=x%y=15%6=3 Since 15/6=2 / return quotient.
30th Jan 2020, 8:21 PM
Jayakrishna 🇮🇳