Never been to DZone Snippets before?

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

About this user

Guildorn Tanaleth

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

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 (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;
}
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS