euclid algorithm

PHP
int Euclid(int a, int b)
{
    int r;
    while(b != 0) 
    {
         r = a % b;
         a = b; 
         b = r; 
    }
    return a; 
} function mcd($a,$b) {
	while($b) list($a,$b)=array($b,$a%$b);
	return $a;
}def MCD(a,b):
    while b != 0:
        a, b = b, a % b
    return afunction gcd(a, b)
    if b = 0
        return a
    else
        return gcd(b, a mod b)

Source

Also in PHP: