Shell script for combinations ncr, Programming Languages

 Find nCr.

 Program

echo -e  "Enter n: \c"

read n

echo -e "Enter r: \c"

read r

i=2

nf=1

temp=`expr $n - $r`

tf=1

rf=1

ncr=1

while test $i -le $n

do

   nf=`expr $nf\*$i`

   i=`expr $i + 1`

done

 

nf=`echo "$nf" | bc`

i=2

while test $i -le $temp

do

  tf=`expr $tf\*$i`

  i=`expr $i + 1`

done

tf=`echo "$tf" | bc`

 

i=2

while test $i -le $r

do

  rf=`expr $rf\*$i`

  i=`expr $i + 1`

done

rf=`echo "$rf" | bc`

temp2=`echo "$nf / $tf" | bc`

ncr=`echo "$temp2 / $rf" | bc`

echo "nCr = $ncr"


Output

sh ncr.sh

Enter n: 5

Enter r: 4

nCr = 5

 

sh ncr.sh

Enter n: 9

Enter r: 4

nCr = 126

 

sh ncr.sh

Enter n: 12

Enter r: 5

nCr = 792

Posted Date: 9/26/2012 8:38:05 AM | Location : United States







Related Discussions:- Shell script for combinations ncr, Assignment Help, Ask Question on Shell script for combinations ncr, Get Answer, Expert's Help, Shell script for combinations ncr Discussions

Write discussion on Shell script for combinations ncr
Your posts are moderated
Related Questions
The ?rst task in the project is to develop a sane system to store change logs and versions of ?les. The simplest approach is to create a "dot" directory in the location of the ?le

Write a Perl program ghici.pl, one of the simplest computer games. The program should generate a random integer between 1 and 1000 and asks the user to guess it. If the user ?nds t

I need to finish my game project within two weeks using XNA. Would you guys can help me to finish it? Thank you

i have a database having field name title and comm. I want to search by name and get the all data remaining title and comm(comm is integer)

Am unable to write to file of type=file in perl script.It does not have any extension.Help me..

Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4

If it is a weekday and it is not a holiday, then you go to work. However, if it is a weekday and it is a holiday, then what you do depends on the weather. If it is raining, you pla

Explain the While Statement - Computer Programming? A 'while statement' is an entry controlled loop statement. When the expression is calculated and the condition is not satisf

What are the Functions in Computer Programming? A program is completed up of one or more functions, with one of these being main(). Function is a self-contained block of progra

You must implement the control mechanism for the robot arm so that it can safely move the blocks from the source pile to their destination, without colliding with any obstacles or