Created
May 17, 2016 09:40
-
-
Save michitomo/270516560bbb7a277d19fcece1adb279 to your computer and use it in GitHub Desktop.
calculate GCD(greatest common divisor) of given two numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ $1 -lt $2 ]; then | |
m=$1;n=$2 | |
else | |
m=$2;n=$1 | |
fi | |
while [ $n -gt 0 ] | |
do | |
r=$(($m%$n)); m=$n; n=$r | |
done | |
echo $m |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment