Jump to content

Greatest common divisor: Difference between revisions

→‎{{header|D}}: remove silly solution
(→‎{{header|D}}: remove silly solution)
Line 437:
 
=={{header|D}}==
<lang d>bool isEven(int number)
{
return number%2 == 0;
}
 
int gcd(int a, int b)
{
if(a == 0)
return b;
else if(b == 0)
return a;
else if(isEven(a) && isEven(b))
return gcd(a>>1, b>>1) << 1;
else if(isEven(a) && !isEven(b))
return gcd(a>>1, b);
else if(!isEven(a) && isEven(b))
return gcd(a, b>>1);
else if(a >= b)
return gcd(a-b, b);
return gcd(a, b-a);
}</lang>
 
===Recursive===
 
<lang d>long gcd(long x, long y) {
if (y == 0)
Line 467 ⟶ 442:
return gcd(y, x%y);
}</lang>
 
 
=={{header|Dc}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.