# shell script to find n!/r!
echo "enter n and r value"
read n r
factn=1
for((i=1; i<=n; i++))
do
factn=`expr $factn \* $i`
done
factr=1
for((i=1; i<=r; i++))
do
factr=`expr $factr \* $i`
done
echo "n!/r! = `expr $factn / $factr`"
OUTPUT
Safi> bash nrfact.sh
enter n and r value
5 2
n!/r! = 60
echo "enter n and r value"
read n r
factn=1
for((i=1; i<=n; i++))
do
factn=`expr $factn \* $i`
done
factr=1
for((i=1; i<=r; i++))
do
factr=`expr $factr \* $i`
done
echo "n!/r! = `expr $factn / $factr`"
OUTPUT
Safi> bash nrfact.sh
enter n and r value
5 2
n!/r! = 60
No comments:
Post a Comment