Greatest common divisor: Difference between revisions

(→‎{{header|REXX}}: added cases of 2nd argument being equal to 0 (zero), and also where an argument is negative. -- ~~~~)
Line 1,794:
<lang rascal>
rascal>gcd_iterative(1989, 867)
int: 51
</lang>
 
===Recursive Euclidean algorithm===
<lang rascal>
public int gcd_recursive(int a, b){
if(b == 0) return a;
else return gcd_recursive(b, a%b);
}
</lang>
An example:
<lang rascal>
rascal>gcd_recursive(1989, 867)
int: 51
</lang>
Anonymous user