Author |
Message |
8749236
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
|
|
|
![](images/spacer.gif) |
TokenHerbz
![](http://compsci.ca/v3/uploads/user_avatars/717170395558e628d9452b.jpg)
|
Posted: 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! |
|
|
|
|
![](images/spacer.gif) |
DemonWasp
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
TokenHerbz
![](http://compsci.ca/v3/uploads/user_avatars/717170395558e628d9452b.jpg)
|
Posted: 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 Razz](http://compsci.ca/v3/images/smiles/icon_razz.gif) |
|
|
|
|
![](images/spacer.gif) |
RandomLetters
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
8749236
|
Posted: 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 Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
|