diff options
author | Igor <pashev.igor@gmail.com> | 2011-01-12 15:33:44 +0300 |
---|---|---|
committer | Igor <pashev.igor@gmail.com> | 2011-01-12 15:33:44 +0300 |
commit | cb9ab4e10b97f91bcf78fc643821851097a54e7e (patch) | |
tree | ac08985c2e405a77d7599f0934561cb6acdbd603 /gcd.cs | |
download | gcd-cb9ab4e10b97f91bcf78fc643821851097a54e7e.tar.gz |
Begin: C, C#, Haskell, Java, Python
Diffstat (limited to 'gcd.cs')
-rw-r--r-- | gcd.cs | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -0,0 +1,32 @@ +using System; + +namespace GCD { + class Program { + static uint gcd2(uint a, uint b) { + uint c; + while (b != 0) { + c = b; + b = a % b; + a = c; + } + return a; + } + + static uint gcdn(uint [] n) { + uint r = n[0]; + for (int i = 1; i < n.Length; i++) + r = gcd2(r, n[i]); + return r; + } + + static void Main(string [] argv) { + uint [] a = Array.ConvertAll<string, uint>(argv, + new Converter<string, uint> + (delegate(string s) {return uint.Parse(s);}) + ); + + Console.WriteLine("{0}", gcdn(a)); + } + } +} + |