Last active
September 23, 2015 08:55
-
-
Save mfrazi/aa4b27705926c977455c to your computer and use it in GitHub Desktop.
Find GCD (Greatest Common Divisor) of two integer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source : http://www.math.wustl.edu/~victor/mfmm/compaa/gcd.c | |
/* Standard C Function: Greatest Common Divisor */ | |
int | |
gcd ( int a, int b ) | |
{ | |
int c; | |
while ( a != 0 ) { | |
c = a; a = b%a; b = c; | |
} | |
return b; | |
} | |
/* Recursive Standard C Function: Greatest Common Divisor */ | |
int | |
gcdr ( int a, int b ) | |
{ | |
if ( a==0 ) return b; | |
return gcdr ( b%a, a ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment