Computer Science Canada Modulus % Help |
Author: | thegadgetman [ Sat Oct 02, 2010 12:09 pm ] | ||
Post subject: | Modulus % Help | ||
Hello I have a questions about Modulus I had this topic covered in college last week and I don't really understand why we use it and how it works totally, so I was wondering if someone could give me an example of it's use in programming and answer a Modulus question for me showing all your work. So heres what I know so far... That it used to give remainders... and a simple modulus calculation can be
But how do you solve if you have say... 5 % 13... the answer should be 5 but how is it 5, I don't understand how that can be. Thanks, I would appreciate some help so I can ace my midterms, sorry if this is easy stuff and seems stupid I am new to programming and very great-full for any help I will receive. |
Author: | jcollins1991 [ Sat Oct 02, 2010 1:42 pm ] |
Post subject: | Re: Modulus % Help |
Modulus returns the remainder after division. In your first example 20 % 6 you get 2 because 20 = 3*6 + 2, similarly in 5 % 13 the answer is 5 because 5 = 13*0 + 5. Wikipedia explains it all pretty well http://en.wikipedia.org/wiki/Modular_arithmetic |
Author: | thegadgetman [ Sat Oct 02, 2010 3:12 pm ] |
Post subject: | Re: Modulus % Help |
Oh yeah haha 13*0 = 0 + 5 doh i feel stupid... I read the Wiki thanks, i did try the wiki but the page you linked was better than the one i was reading thanks again. |