26 December 2011

UNIX shell script to find the factorial of given number

$ cat>factorial.sh
echo enter value of n
read n
If [$n –eq 0]
then
echo factorial of given number is 1
fi
If [$n -1t 0]
then
echo factorial of given number is not possible
else
temp = ‘expr $n – 1’
while [ $temp –gt 1]
do
$n = ‘expr $n \* $temp’
temp = ‘expr $temp – 1’
done
echo factorial of given number is $n
fi

1 comments:

Post a Comment