Greatest Common Denominator function
int gcd(int x, int y) { int a, b; if (x<y) {a = y; b = x; } else if (x>y) {a = x; b = y; } else {return x; } do { int r = a % b; a = b; b = r; } while (b != 0); return a; }
DZone Snippets > Minimiscience > GCD
12309 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
int gcd(int x, int y) { int a, b; if (x<y) {a = y; b = x; } else if (x>y) {a = x; b = y; } else {return x; } do { int r = a % b; a = b; b = r; } while (b != 0); return a; }