Monday, 9 April 2018

Shell script to find the ncr value

#Script to find the ncr value
echo "enter values of n and r"
read n
read r
t=0 i=1
a=1 b=1
c=1 d=0
while [ $i -le $n ]
do
a=`expr $a \* $i`
i=`expr $i + 1`
done
i=1
while [ $i -le $r ]
do
b=`expr $b \* $i`
i=`expr $i + 1`
done
i=1
d=`expr $n - $r`
while [ $i -le $d ]
do
c=`expr $c \* $i`
i=`expr $i + 1`
done
i=`expr $b \* $c`
t=`expr $a / $i`
echo "result=$t"



OUTPUT
Safi>sh ncr.sh
enter values of n and r
5
3
result=10

No comments:

Post a Comment