Computer Science Canada

Turing Program

Author:  mike cra [ Wed Oct 20, 2010 7:11 pm ]
Post subject:  Turing Program

I was able to do Permutations n combination

Anyone able to do the GCD or LCM or the Number Theory? I have no clue :S

Author:  SNIPERDUDE [ Wed Oct 20, 2010 10:42 pm ]
Post subject:  RE:Turing Program

Let's tackle this one at a time then. Starting with LCM, what have you tried? What aspect are you stuck with? We can't do your homework for you, but we can help you understand whatever it is you're stuck on.

Author:  Carey [ Thu Oct 21, 2010 6:56 pm ]
Post subject:  RE:Turing Program

For GCD, you'll want to use recursion and Euclid's Algorithm

Example (pseudo-code, will not run):
code:

fcn gcd (a, b :int) : int
   if b is 0 then return a
   if anything else then return gcd (b, a mod b) %this is the recursive call. It will call the function from inside itself. At first it's hard to wrap your head around.
end


You can then use the GCD method in finding the LCM by following the formula here


: