Tuesday, August 25, 2009
Shell Scripting #0017: Factorial - How to create Factorial Program in Shell Script?
All these while, I was under an impression that my blog is helpful only to professionals. Not anymore, as one of a student asked me how to create factorial program in Shell Script.
This is for him, Thank you Vignesh for reaching out to me.
Factorial
on=0
fact=1
echo -n "Enter number to find factorial : "
read n
on=$n
while [ $n -ge 1 ]
do
fact=`expr $fact \* $n`
n=`expr $n - 1`
done
echo "Factorial for $on is $fact"
This is for him, Thank you Vignesh for reaching out to me.
Factorial
#!/bin/bashn=0
on=0
fact=1
echo -n "Enter number to find factorial : "
read n
on=$n
while [ $n -ge 1 ]
do
fact=`expr $fact \* $n`
n=`expr $n - 1`
done
echo "Factorial for $on is $fact"
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment