diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2013-12-21 11:45:47 +0400 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2013-12-21 11:45:47 +0400 |
commit | f9787e0c62fda6dbc1027776cdf1515622b974a2 (patch) | |
tree | de59418874ecabe546a4a2bbdb19557c59073b3a | |
parent | 4b5bdac9bd93ac97e3f99a14d3d28a70cd33607c (diff) | |
download | gcd-f9787e0c62fda6dbc1027776cdf1515622b974a2.tar.gz |
PHP
-rw-r--r-- | gcd.php | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -0,0 +1,28 @@ +<?php + +function gcd2($a, $b) +{ + $c = 0; + while ($b != 0) + { + $c = $b; + $b = $a % $b; + $a = $c; + } + return $a; +} + +function gcd($numbers) +{ + $r = 0; + foreach ($numbers as $n) + { + $r = gcd2($n, $r); + } + return $r; +} + +print gcd(array_slice($argv, 1)); + +?> + |