Over a million developers have joined DZone.

Greatest Common Denominator Function

·
This function returns the greatest common denominator (GCD) of its arguments.

int gcd(int x, int y) {
 int a, b;
 if (xy) {a = x; b = y; }
 else {return x; }
 do {
  int r = a % b;
  a = b;
  b = r;
 } while (b != 0);
 return a;
}
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}