summaryrefslogtreecommitdiff
path: root/gcd.cs
diff options
context:
space:
mode:
authorIgor <pashev.igor@gmail.com>2011-01-12 15:33:44 +0300
committerIgor <pashev.igor@gmail.com>2011-01-12 15:33:44 +0300
commitcb9ab4e10b97f91bcf78fc643821851097a54e7e (patch)
treeac08985c2e405a77d7599f0934561cb6acdbd603 /gcd.cs
downloadgcd-cb9ab4e10b97f91bcf78fc643821851097a54e7e.tar.gz
Begin: C, C#, Haskell, Java, Python
Diffstat (limited to 'gcd.cs')
-rw-r--r--gcd.cs32
1 files changed, 32 insertions, 0 deletions
diff --git a/gcd.cs b/gcd.cs
new file mode 100644
index 0000000..0825cea
--- /dev/null
+++ b/gcd.cs
@@ -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));
+ }
+ }
+}
+