This is a shell script using git bash. would like to replace the while loop with for loop or to use function.
This is a shell script using git bash. would like to replace the while loop with for loop or to use function.
echo "---------------------------------------"
echo "..........Task 1........."
echo "---------------------------------------"
echo;echo
echo "Enter you name: "
read name
echo -n " WELCOME!!! $name"
echo;echo
#Display to get the user input for number for which multiples are to be found
echo "Enter the number to find multiples:"
read num
#Display the minimum and maximum value of range
echo "Enter the minimum and maximum range of values to display: "
read min max
#initializing i to minimum value
echo
i=$min
#initialize 0 to index
count=0
#looping from minimum to maximum values given by the user
echo "Multiples of $num in the given range [$min,$max]: "
while [ $i -le $max ]
do
#checking if i value is divisible by the number
if(($i % $num == 0))
then
if(( $i % 2 == 0 ))
then
echo "$i"
((count++))
#display the multiples in given range
fi fi
((i++))
done
echo "Count of multiples from $min to $max is $count"
#display the count of multiples in the given range
echo "Thank you"
Step by step
Solved in 4 steps with 3 images