# Define myEuclid as GCD of two numbers

Posted 9 years ago
2265 Views
|
2 Replies
|
0 Total Likes
|
 Hello,Euklid[a0_, b0_] :=  Module[     {a = a0, b = b0},     While[a*b != 0, {a, b} = {b, Mod[a, b]}];     a        ];did work fine. How can I define a new function that gives me the GCD of two numbers without using the command "Module" and without using the way above when it says "{a,b} = {b, Mod[a,b]}". I mean: Without writing two commands into { and }. I separately want to tell mathematica: a = b   and   b = Mod[a,b].Thank you for your help
2 Replies
Sort By:
Posted 9 years ago
 Hi,I'd like something that goes in this direction that uses "While" or something like this.gcd[a_,b_] :=      If[a==b,Print[b], While[b!=0,If[a>b,...I just don't get it ;/
Posted 9 years ago
 Not clear to me what you want. Maybe something recursive like below?gcd[1, _] = 1;gcd[_, 1] = 1;gcd[a_, a_] := agcd[a_, b_] := gcd[b, Mod[a, b]]
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.