Saturday, June 9, 2018

SHELL SCRIPT TO FIND FACTORIAL OF A GIVEN NUMBER

echo "Enter the number"
read n
f=1
while [ $n -gt 0 ]
do
f=`expr $f \* $n`
n=`expr $n - 1`
done
echo "factorial= $f"

                                               OUTPUT

biswarup@biswarup-desktop:~$ sh
$ sh fact.sh
Enter the number
3
factorial= 6
$

No comments:

Post a Comment