Thursday 14 May 2015

Shell Script: To find the factorial of a number

To execute this script in bash shell must and should provide the execute permision. To give execute permission in user level use the command:


chomd u+x file_name.sh


 


If you are using sh shell no need of providing permission
echo "enter the number"
read n
fact=1
while [ $n -gt 0 ]
do
     fact=`expr $fact \* $n`
     n=`expr $n - 1`
done
echo "factorial=$fact"

No comments:

Post a Comment