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 trialMilosz Drozd
9,500 Pointsi do get how 5 % 3 = ? or using % in C# arithmetics works in general?Hard to find explaination in my language aswell.
it is not really clear for me how to use %. if I have like 5 % 3 do I 5:3 =1,67... or ...
Would you guys be so kind and add few examples of how that works ? God bless ya.
2 Answers
Steven Parker
231,248 PointsIt's known as the "remainder" operator, and it gives you what's left over after an integer divide. So, for your example, 5 divided by 3 is 1, but with 2 "left over".
So 5 % 3 = 2
. And 8 % 2 = 0
since it divides evenly. Using it with 2 as the second operand is a good way to test a number for even (0) or odd (1).
Milosz Drozd
9,500 Pointsthank you Sir