Skip to content

Instantly share code, notes, and snippets.

@michitomo
Created May 17, 2016 09:40
Show Gist options
  • Save michitomo/270516560bbb7a277d19fcece1adb279 to your computer and use it in GitHub Desktop.
Save michitomo/270516560bbb7a277d19fcece1adb279 to your computer and use it in GitHub Desktop.
calculate GCD(greatest common divisor) of given two numbers
#!/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