fact()
{
if(( $1<=1 ))
then
echo 1
else
(( t=$1-1 ))
(( res=`fact $t` * $1 ))
echo $res
fi
}
echo -e "Enter an integer: \c"
read n
if(( n<0 ))
then
echo ERROR: Invalid argument
else
echo -e "Factorial of \"$n\" is `fact $n`"
fi
No comments:
Post a Comment