Skip to content

Instantly share code, notes, and snippets.

@eshacker
Created January 28, 2016 10:15
Show Gist options
  • Save eshacker/66b0b3e2e108a18d3d18 to your computer and use it in GitHub Desktop.
Save eshacker/66b0b3e2e108a18d3d18 to your computer and use it in GitHub Desktop.
Finding GCD recursively
using System;
class Solution {
static void Main(String[] args) {
var numbers = Console.ReadLine().Split(' ');
var x = int.Parse(numbers[0]);
var y = int.Parse(numbers[1]);
Console.WriteLine(gcd(x, y));
}
static int gcd(int x, int y){
if(x % y == 0){
return y;
}
else {
var min = Math.Min(x, y);
var max = Math.Max(x, y);
return gcd(max%min, min);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment