Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# modulus operator [closed]

Tags:

c#

modulus

I can write the program

int a = 3; int b = 4;  Console.WriteLine(a % b); 

The answer I get is 3. How does 3 mod 4 = 3???

I can't figure out how this is getting computed this way.

like image 938
Ben Ziegler Avatar asked Aug 06 '10 20:08

Ben Ziegler


1 Answers

I wasn't quite sure what to expect, but I couldn't figure out how the remainder was 3.

So you have 3 cookies, and you want to divide them equally between 4 people.

Because there are more people than cookies, nobody gets a cookie (quotient = 0) and you've got a remainder of 3 cookies for yourself. :)

like image 115
quantumSoup Avatar answered Sep 19 '22 15:09

quantumSoup