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
In combat simulation software, exploding land mines cause damage to military vehicles. In addition to the damage done to the vehicles themselves, we are interested in the number of

Really urgent help needed with Javascript. I have this website: I">https://www.theppcpresents.com/globe13/#/home I need to remove the video on the slider so that it only sho

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

Problem 6. Demonstrate how and when can you use the commands- vi, cat, chmod, grep, man, pwd, ps, kill, mkdir, rm demonstrating how and when the above 10 commands can be

Create a Money data structure that is made up of amount and currency.  (a) Write a constructor for this data structure   (b)  Create accessors for this data structure (c)

Eclipse Jsp Project. I am making a a project on my website and i was making a help support page on which the user can submit their question and the question is saved to a text file

1- Allocate array with 32bit 100 element 2- Prompt the user to enter the maximum or the upper bound of the random value 3- Read the value and use it generate random numbers to init

Implement the Prim's algorithm with array data structure as described in slide 12 of the file 04mst.ppt. Your program should have a runtime complexity of O(n2) and should be as eff

program take integer from user and print in alphabets

how do u define a letter in python "NameError: name ''r'' is not defined"