Jump to content

Greatest common divisor: Difference between revisions

m (Added postscript function that requires no external lib)
Line 445:
Console.Read();
}
{
 
// Greatest Common Denominator using Euclidian Algorithm
private static int gcd(int a, int b)
// Gist: https://gist.github.com/SecretDeveloper/6c426f8993873f1a05f7
private static int gcd(int a, int b)
int t;
{
 
return b==0 ? a : gcd(b, a % b);
// Ensure B > A
if (a > b)
{
t = b;
b = a;
a = t;
}
 
// Find
while (b != 0)
{
t = a % b;
a = b;
b = t;
}
 
return a;
}
</lang>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.