Code In Tech - The Ultimate World of Computer Technology

Saturday, 12 May 2012

Shell script to find the factorial of a given no.

SOURCECODE:

echo “Enter the no:“
read n
i=1
a=1
d=0
if [ $n –eq $d ]
then
     echo $a
else
while [ $i –le  $n ]
do

            a=`expr $a \* $i`
            i=`expr $i + 1`
done
fi
echo “Ans:“ $a

OUTPUT:

Enter the no:
4
Ans:24  

No comments :

Post a Comment