Modulus giving 2 why?


I think i’m having a drawn out brain fart.
I need some help understanding why this happens
printf(“11/3 = %d with a remainder of %d\n”, 11/3, 11%3);
and then…
Output is:
11/3 = 3 with a remainder of 2

why is the modulus reporting this way?
i would have expected .6667 or something rounded up


Because that’s exactly what the modulus operator is intended to do. It returns the remainder from a division.

When you divide 11 by 3, you’re asking, "How many threes are there in eleven? You get 3 whole threes, and two pieces of a three. 3 and 2 thirds. 3 and 2/3. The modulus operator returns the remainder, which is the numerator of the remaining fraction of a three, which is 2.

.66667 is what you get when you divide the modulus by the original divisor. Two pieces of a three = 2/3 = 0.6667.


Hmm okay… so I’m sure this is jumping ahead a bit but how would I use the modulus to get the division by 1 result? And possibly round it.


I’ve rewritten my answer above, and hopefully it’s more clear. Does that help any?


OHH okay I see. I never thought of these things dealing in fractions really. Just floting points.
learning alot.