C# - Recursive Euclidean Algorithm (for GCD)

By , 12/22/2011
(1 ratings)
A recursive algorithm used to find the GCD of two numbers.
/// <summary>
/// Finds the GCD of two numbers. (Recursively)
/// </summary>
public int gcd(int a, int b)
     if(a == 0)
          return a;
     if(b == 0)
          return b;

          return gcd(a % b, b);
          return gcd(a, b % a);
Tagged with gcd, euclid, algorithm, recursive.



Log in, to comment!

Related Snippets