You are on page 1of 2

CONTENT BEYOND SYLLABUS - 2

AIM : Shell script to compute GCD and LCM of two


numbers

SOURCE CODE:
clear
echo "Enter two intergers"
read m n
echo " To find GCD and LCM"
echo "===================="
echo "given two numbers are"
echo "m= $m and n=$n"
temp=`expr $m \* $n`
while [ $m != $n ]
do
if [ $m -gt $n ]
then
m=`expr $m - $n`
else
n=`expr $n - $m`
fi
done
echo GCD=$n
lcm=`expr $temp / $n`
echo LCM=$lcm
OUTPUT:

Enter two intergers

20 30

To find GCD and LCM


===============
given two numbers are

m= 20 and n=30

GCD=10

LCM=60

You might also like