Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Basics (Retired) Perform Order of Operations

C# Basics match questions. Can't understand what you do with the % in the math question.

8 * 7 + 8 % 5 + 6 / 2 = ????

3 Answers

Steven Parker
Steven Parker
231,269 Points

That's the modulus operator.

Also called "modulo" or "remainder", the modulus operator performs a division operation but instead of returning the result it returns the remainder. For example, 12 % 7 = 5 because if you divide 12 by 7 the result is 1 but you have 5 left over. For expression evaluation, it has the same precedence as the multiply and divide operators.

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! The % sign is used as the modulus/modulo operator. This operator returns the remainder of the division of the 2 numbers. For example, in this case, the 8 % 5 would return a 3. This is because 8 is divisible by 5 with a remainder of 3. Eight divided by five is equal to 1 and 3/5. The three here is the remainder.

Hope this helps! :sparkles:

Ok thanks I understand now