|
| 1 | +static void Main(string[] args) |
| 2 | +{ |
| 3 | + Console.WriteLine("GCD of {0} and {1} is {2}", 1, 1, gcd(1, 1)); |
| 4 | + Console.WriteLine("GCD of {0} and {1} is {2}", 1, 10, gcd(1, 10)); |
| 5 | + Console.WriteLine("GCD of {0} and {1} is {2}", 10, 100, gcd(10, 100)); |
| 6 | + Console.WriteLine("GCD of {0} and {1} is {2}", 5, 50, gcd(5, 50)); |
| 7 | + Console.WriteLine("GCD of {0} and {1} is {2}", 8, 24, gcd(8, 24)); |
| 8 | + Console.WriteLine("GCD of {0} and {1} is {2}", 36, 17, gcd(36, 17)); |
| 9 | + Console.WriteLine("GCD of {0} and {1} is {2}", 36, 18, gcd(36, 18)); |
| 10 | + Console.WriteLine("GCD of {0} and {1} is {2}", 36, 19, gcd(36, 19)); |
| 11 | + for (int x = 1; x < 36; x++) |
| 12 | + { |
| 13 | + Console.WriteLine("GCD of {0} and {1} is {2}", 36, x, gcd(36, x)); |
| 14 | + } |
| 15 | + Console.Read(); |
| 16 | +} |
| 17 | + |
| 18 | +// Greatest Common Denominator using Euclidian Algorithm |
| 19 | +// Gist: https://gist.github.com/SecretDeveloper/6c426f8993873f1a05f7 |
| 20 | +static int gcd(int a, int b) |
| 21 | +{ |
| 22 | + return b==0 ? a : gcd(b, a % b); |
| 23 | +} |
| 24 | + |
0 commit comments