diff options
-rwxr-xr-x | gcd.sh | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -0,0 +1,20 @@ +#!/bin/sh + +gcd2() { + if test $2 = 0 ; then + echo $1 + else + gcd2 $2 `expr $1 % $2` + fi +} + +gcdn() { + r=$1; shift + for n in $*; do + r=`gcd2 $r $n` + done + echo $r +} + +gcdn $* + |