Write a program to find factorial of a given number.

clear
echo "Enter the number to find the Factorial"
read f
if [ $f -eq 0 -o $f -eq 1 ]
then
echo "factorial is 1"
else

fact=1
i=2
while [ $i -le $f ]
do
fact=`expr $i \* $fact`
i=`expr $i + 1`
done
echo "factorial of $f is $fact"
fi

OutPut

Enter the number to find the Factorial
5
factorial of 5 is 120

No comments:

Post a Comment