#!/bin/sh
echo-n "input the first number :"
readm
echo-n "input the second number :"
readn
num1=$m
num2=$n
r=`expr$m % $n`
while[ $r -ne 0 ]
do
m=$n
n=$r
r=`expr$m % $n`
done
echo"最大公约数是:$n"
min=`expr$num1 \* $num2 / $n`
echo"最小公倍数是:$min"
你根据需要自己修改吧~
#!/bin/bash
echo -n "Please input the first integer: "
read arg1
echo -n "Please input the second integer: "
read arg2
echo $arg1 $arg2
# remainder=`expr $first % $second`
calculateGCDnLCM ()
{
first=$1
second=$2
if [[ $first -le $second ]]
then
little=$first
great=$second
else
little=$second
great=$first
fi
echo $little $great
GCD=$little
LCM=$great
# if [ "$GCD"x == "0"x ]
if [[ $GCD -eq 0 ]]
then
echo "0 divisor !"
exit 1
fi
while [[ $little -gt 0 ]]
do
GCD=$little
# little=`expr $great % $little`
little=$(($great % $little))
great=$GCD
echo "-- " $little
done
((LCM=$first * $second))
LCM=$(($LCM/$GCD))
echo -n -e "GCD: " $GCD
echo -n -e "\nLCM: " $LCM
}
calculateGCDnLCM $arg1 $arg2