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

Username:   Password: 
 RegisterRegister   
 Can any1 help me to explain how does code "mod" works???
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
8749236




PostPosted: Mon Jan 10, 2011 11:35 am   Post subject: Can any1 help me to explain how does code "mod" works???

What is it you are trying to achieve?
i'm trying to understand how does this code "mod" works..

What is the problem you are having?
i don't know how does this code "mod" works..

Describe what you have tried to solve this problem
finding the releations of the number before calculation and after..


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
here is a code that is using "mod" to find factors...

Turing:


/*
 2011-01-10 Monday
 Chapter 9 Excerise
 */


% declaring variables or constants..
var integer : int

% prompt user to enter a integer..
put "Please input an integer.."
get integer

put "The factors of ", integer, " are:"

% finding factors
for factor : 1 .. integer

    % try 1 by 1..
    if integer mod factor = 0 then
        put factor
    end if

end for




Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon Jan 10, 2011 11:46 am   Post subject: RE:Can any1 help me to explain how does code "mod" works???

So we have a copy of Turing's documentation available at http://compsci.ca/holtsoft/doc/ which explains all of Turing's build in features, including mod
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
TokenHerbz




PostPosted: Mon Jan 10, 2011 11:48 am   Post subject: RE:Can any1 help me to explain how does code "mod" works???

well that is a factor? A number the divides evenly into a larger number.

If we have the number 12. it goes and checks numbers up to 12.

for i: 1 .. 12
if i mod 12 = 0 (if it divides evenly)
put i mod 12 %%So 3 goes into 12 right, it will print
end if
end for

%%EDIT SPEEDY TONY WINS!
DemonWasp




PostPosted: Mon Jan 10, 2011 11:59 am   Post subject: RE:Can any1 help me to explain how does code "mod" works???

mod is one of Turing's operators. These include things like +, -, *, /, and **. Where + tells Turing "add the thing to the left with the thing to the right", mod tells Turing "divide the thing to the left BY the thing to the right, then take the remainder".

So saying "A mod B" means "the remainder you get when you divide A by B".

@Token: You've got your modulus args backwards, and you're missing a then.
TokenHerbz




PostPosted: Mon Jan 10, 2011 12:04 pm   Post subject: RE:Can any1 help me to explain how does code "mod" works???

i didn't test it out, and i was explaining how its used. infact its not even in a [code] tag because i wrote it in the quick reply. tiss it is backwards lol but it would of gave him a good oportunity to "look into why it dont work" thus its a WIN for helping. Razz
RandomLetters




PostPosted: Mon Jan 10, 2011 4:41 pm   Post subject: RE:Can any1 help me to explain how does code "mod" works???

mod is the operator that takes the remainder during division (like in long division by hand).

so for example,
5 mod 2 = 1

since 5/2 = 2 remainder 1


its sorta related to div, which does integer division

5 = (5 div 2) * 2 + (5 mod 2)
= 2 * 2 + 1
8749236




PostPosted: Thu Jan 20, 2011 10:35 am   Post subject: RE:Can any1 help me to explain how does code "mod" works???

thank you for helping, i understand now Smile
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  [ 7 Posts ]
Jump to:   


Style:  
Search: