Wednesday, 19 June 2013

Write a shell script to accept a number and compute it's factorial?

echo "Enter the number whose factorial is to be computed"
read num
temp=`expr $num - 1`
while [ $temp -ge 1 ]
do
num=`expr $num \* $temp`
temp=`expr $temp - 1`
done
echo "The factorial of number is : $num"             


OUTPUT :

Enter the number whose factorial is to be computed
5
The factorial of number is : 120      

No comments:

Post a Comment