Showing posts with label divisible in a range. Show all posts
Showing posts with label divisible in a range. Show all posts

Saturday, 6 April 2019

Shell script to read in two numbers and display the number divisible by the first number in the given range

Program
echo "Enter two numbers"
read m n
echo "Numbers divisible by [$m] in the range [$m] to [$n]"
for((i=$m;i<=$n;i++))
do
    div=`expr $i % $m`
    if test $div -eq 0
    then
         echo $i
    fi
done



OUTPUT
Safi $ bash samp.sh
Enter two numbers
3 20
Numbers divisible by [3] in the range [3] to [20]
3
6
9
12
15
18