Greatest common divisor: Difference between revisions

Content added Content deleted
No edit summary
Line 893: Line 893:
=={{header|Elena}}==
=={{header|Elena}}==
{{trans|C#}}
{{trans|C#}}
ELENA 3.3 :
ELENA 3.4 :
<lang elena>import system'math.
<lang elena>import system'math.
import extensions.
import extensions.

gcd = (:a:b)
gcd(a,b)
[
[
var $a := a.
var i := a.
var $b := b.
var j := b.
while($b != 0)
while(j != 0)
[
[
var tmp := $a.
var tmp := i.
$a := $b.
i := j.
$b := tmp mod($b).
j := tmp mod(j).
].
].
^ $a.
^ i
].
]

printGCD = (:a:b)
printGCD(a,b)
[
[
console printLineFormatted("GCD of {0} and {1} is {2}", a, b, gcd(a,b)).
console printLineFormatted("GCD of {0} and {1} is {2}", a, b, gcd(a,b)).
].
]

program =
public program
[
[
printGCD(1,1).
printGCD(1,1).
Line 927: Line 927:
printGCD(36,19).
printGCD(36,19).
printGCD(36,33).
printGCD(36,33).
].</lang>
]</lang>
{{out}}
{{out}}
<pre>
<pre>