Saturday, 16 July 2016

Write a shell script in Linux/Unix to find Factorial of a given number.


echo "ENTER A NUMBER-"
read n
fct=1
i=1
while test $i -le $n
do
fct=`expr $fct \* $i`
i=`expr $i + 1`
done
echo "THE FACTORIAL OF THE NUMBER IS -" $fct


OUTPUT:

ENTER A NUMBER-
5
THE FACTORIAL OF THE NUMBER IS-120







No comments:

Post a Comment

Popular Posts