Greatest Common Denominator

Non-Recursive implementation of the Euclidean Algorithm to find the greatest common denominator (GCD) between two numbers.


public int GCD(int a, int b)
{
while (a != 0 && b != 0)
{
if (a > b)
a %= b;
else
b %= a;
}

if (a == 0)
return b;
else
return a;
}


Reference: http://www.vcskicks.com/euclidean-gcd.php


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: