tshm
1/31/2014 - 5:49 AM

gcd.sh

#!/bin/bash
x=$1
y=$2
(( $x < $y )) && { x=$2 && y=$1 ;}
while (( $y != 0 ))
do
   m=$(( $x - $(( $x / $y )) * $y ))
	 (( $m < $y )) && { x=$y && y=$m ;} || { x=$m ;} 
done

echo "gcd of $1 and $2 is $x"
echo "lcm of $1 and $2 is $(( $1 * $2 / $x ))"