Back to questions
JuniorTheoryCommon
What does the program print (lines separated by spaces)?
Console.WriteLine(7 / 2);
Console.WriteLine(-7 % 3);3 -1
- Expecting
3.5: dividing oneintby another drops the fraction, so7 / 2is3. - Expecting a non-negative remainder, as in math: in C# the remainder takes the sign of the dividend, so
-7 % 3is-1.
- How would you change the first line so that it prints
3.5? - What does
7 % -3evaluate to, and why?