1.below is my code for shell script using gitbash l want it to produce an output like: 2→→1x2 6→→2x3 12→→3x4 20→→4x5 30→→5x6 and that when the number is divisible by 5 it mentions it #reading the input number from user read -p "Enter number: " number #setting count to 0, to hold total of this kind of numbers count=0 #loop till less than or equal to the user entere nunber for (( i=1;i<=$number;i++ )) do #this loop is to find the factors of the numbers from 1 to user given numbers for ((j=1;j<=i;j++)) do #checking for the factor of the number by checking if the number #is divisble or not if [ `expr $i % $j` -eq 0 ] then #if we found factor of the number, then check if the division of the #present factor with the number is equal to factor+1, i.e for example # take 12, lets say the factor of 12 is 3, so if 12/3 == 3+1 then we can say # that this number can be formed by multiplying two successer numbers 3 and 4 which 12 if [ `expr $i / $j` -eq `expr $j + 1` ] then #printing the number echo $i #counting the numbers count=`expr $count + 1`; fi fi done done #printing the count echo "The total numbers are: "$count
1.below is my code for shell script using gitbash l want it to produce an output like:
2→→1x2
6→→2x3
12→→3x4
20→→4x5
30→→5x6
and that when the number is divisible by 5 it mentions it
#reading the input number from user
read -p "Enter number: " number
#setting count to 0, to hold total of this kind of numbers
count=0
#loop till less than or equal to the user entere nunber
for (( i=1;i<=$number;i++ ))
do
#this loop is to find the factors of the numbers from 1 to user given numbers
for ((j=1;j<=i;j++))
do
#checking for the factor of the number by checking if the number
#is divisble or not
if [ `expr $i % $j` -eq 0 ]
then
#if we found factor of the number, then check if the division of the
#present factor with the number is equal to factor+1, i.e for example
# take 12, lets say the factor of 12 is 3, so if 12/3 == 3+1 then we can say
# that this number can be formed by multiplying two successer numbers 3 and 4 which 12
if [ `expr $i / $j` -eq `expr $j + 1` ]
then
#printing the number
echo $i
#counting the numbers
count=`expr $count + 1`;
fi
fi
done
done
#printing the count
echo "The total numbers are: "$count
Step by step
Solved in 4 steps with 5 images