Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Shutdown
#20
Would you mind not flipping out on us? This isn't about your grade in math, it's about understanding a very useful operation that you will need for programming in any language.

Okay, I'll try once more to explain, but I'll try to jam everything into one post.

Don't get intimidated because this operator is text instead of a symbol. It doesn't make much sense because it isn't a function, but an operator. I'm going to use the "@" symbol instead of "Mod" (or "%", because that get's confused with percentage). Got it?

So, sample problem number 1 goes like this:
13 @ 5 = ?

Now, take it in steps. Find out what "13 / 5" equals. It's 2.6, but there is a nasty decimal at the end. We don't want him so we round down to 2. Now we need to multiply this 2 by the number we divided by. Normally, this would give you the same number you started with (13), but because we rounded down, it won't.

5 * 2 = 10

We now have 10. This is telling us that 10 is the highest number below 13 that can be divided by 5 evenly. Knowing that, we just compare 10 and 13.

13 - 10 = 3

3 is our answer. The remainder of a division problem is the difference between the closest perfect divide (that means that it doesn't have a decimal answer) and the number we started with.


I don't know how you learn, so I'm going to try it in terms of fractions.

67 @ 10 = ?

Let's divide using the calculator first.

67 / 10 = 6.7

In this method, we don't throw the decimal out yet. I've used "10" to make this much easier to do. Split the number according to the space right before the decimal.

So, we have:

6

And

.7

We need to figure out what .7 is in terms of something over 10 (If it were 67 @ 8, we'd figure it out over 8 instead. Yhis rule applies for all problems, not just 10 and 8!)

x / 10 = .7

Simple algebra here. Multiply both sides by 10 and you get:

x = 7

Guess what? The answer is 7. If we were in school and had to divide and find that remainder, 6 would be the answer (67 / 10 rounded down) and 7 would be the remainder (67 @ 10).


I hope I kind of help. It's easiest to use mod with 10, because it works perfectly.

85 @ 10 = 5
42 @ 10 = 2
70 @ 10 = 0

But, as I showed...

30 @ 5 = 0
29 @ 5 = 4
28 @ 5 = 3
27 @ 5 = 2
26 @ 5 = 1
25 @ 5 = 0

You'll get used to it. I do it in my head a slightly different way. I round up instead and then subtract the other way, but they both work.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)