Start New Discussion within our **Software Development Community** # Two ways to implement the GCD

```
//recursive method
//
public static int gcd(int x, int y)
{
if (y == 0) return x;
else return gcd(y, x % y);
}
//more like the ancient greek Euclid originally devised it
//
public static int gcd2(int x, int y)
{
while (x != y)
{
if (x > y)
{
x = x - y;
}
else
{
y = y - x;
}
}
return x;
}
```

The article starter has earned a lot of community kudos, and such articles offer a bounty for quality replies.