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
what is the difference between class and interface

how to save bulk entries at a time using collections?

Your program can be invoked with option: -d date, where date is entered in dd/mm/yyyy format. In this case, it must only print the following string: Found cookies expiring bef

Genetic Diseases Problem Description Many human diseases could be controlled by the knowledge of the gene's structure and pattern. The human gene could be represented by fou

The aims of this assignment are to:    Provide experience in the use of a modern Integrated Development Environment (specifically NetBeans running on a Linux platform) for t

While working in the eHealth Applied Research lab at Mohawk College, you are asked to transform an xml file into an XHTML representationusing XSLT for display in a browser.The xml

Use an insertion sort to sort an array (sequence) of long word integers. The size of the list will appear just before the list itself. Use the same labels as in this example: LE

I have doubt in this section .do-while loop.could you able to clear it for me.

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

I need to do image reconstruction using Neural Network using Matlab