Here is the code for my bash script to calculate factorials
read -p "Please enter the number " number
while ([ $number -gt 0 ])
do
factorial=1
for ((i=$number;i > 0;i--))
do
factorial=$((factorial * $i))
done
echo "The factorial of the " $number " is " $factorial
number=$((number - 1))
done
This prints out the factorial of all the numbers ranging from {input:1}
Everything looks right except for the factorial of a few. The output is given below.
As you can see the factorials of certain numbers are negative values. I understand from the online forums that the bash script usually breaks when calculating factorial of bigger numbers but these negative values don't seem to be common as far as I could dig online. If someone could throw some light on the reason for it, it could greatly help me in my learning. Thank you!