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      

Comments

Popular posts from this blog

Write a program to add two number using inline function in C++?

Traversing of elements program with algorithm and Flowchart