Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Mod Help!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
aqazwsx1




PostPosted: Wed Jan 28, 2009 5:20 pm   Post subject: Mod Help!

Hi, I was wonder how the mod function works? Why does 2 mod 7 =2? Thanks! Very Happy
Sponsor
Sponsor
Sponsor
sponsor
saltpro15




PostPosted: Wed Jan 28, 2009 5:24 pm   Post subject: RE:Mod Help!

the mod is the remainder left over after the numbers are divided
jbking




PostPosted: Wed Jan 28, 2009 5:29 pm   Post subject: RE:Mod Help!

Mod is simply the remainder when a division is done. Another way to think about this is the following if you want a more technical interpretation:

a mod b = x where x+bk = a for some integer k.

Note, that x doesn't have to be between 0 and b-1 though this is usually how it is expressed.
aqazwsx1




PostPosted: Wed Jan 28, 2009 5:36 pm   Post subject: Re: Mod Help!

doesn't 2 mod 7 = 6 ? Why is it 2 ?
Tony




PostPosted: Wed Jan 28, 2009 5:44 pm   Post subject: RE:Mod Help!

how do you figure it to be 6?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
aqazwsx1




PostPosted: Wed Jan 28, 2009 5:48 pm   Post subject: Re: Mod Help!

2/7 so , you add a "0. " so you make the 2 into a 20 , then you find 7*2=14 , so 20-14=6
jbking




PostPosted: Wed Jan 28, 2009 5:55 pm   Post subject: Re: Mod Help!

aqazwsx1 @ Wed Jan 28, 2009 3:36 pm wrote:
doesn't 2 mod 7 = 6 ? Why is it 2 ?


No, but 2 mod 7 = 9, since 7+2=9 which means that for k=1 the expression 7k+2 evaluates to 9, in case you were looking at the number upside down.

This presumes that you understand some basics on division, which can be structured in the following way:
a divided by b gives a quotient of c and a remainder of d satisfies the following equation:

b*c+d = a

Thus, if we take 2 and divide it by 7, there is a quotient of 0 and a remainder of 2, not 6.
aqazwsx1




PostPosted: Wed Jan 28, 2009 6:15 pm   Post subject: Re: Mod Help!

ok thanks
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: