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
Multithreaded Calculator In this Lab, you will be implementing a simple multithreaded calculator. Our calculator will accept expressions as infix notation text strings consist

I need help programming an arduino uno to scan an ean-8 student barcode and display their name and id on computer. This is a capstone project.

The GuessingGame class contains a skeleton for a program to play a guessing game with the user. The program should randomly generate an integer between 1 and 10 and then ask the us

The aim of this task is to gain experience in using the popular Web languages XSLT, XQuery, DTD, XML Schema and RDF. The Content: The University is organizing a stage show wh

Design an application that opens and analyses word files. Requirements: Create an application that analyses text documents. It should open a text file, read each word into an ap

Implement a two-dimensional table in Prolog. Your program will contain: An insert_entry predicate that takes a table, row, column and an entry and inserts the entry at the g

Question: (i) Each time a security mechanism is installed or deleted in a Digital UNIX system, SIA is involved. Draw a Security Integration Architecture diagram. (ii) How

Introduction Currently, Omega has 178 stores UK wide. Most cities and large towns within the UK are catered for by Omega. Omega began in 1960's selling various makes of telep

Define Functions with no arguments and no return values? When a function has no arguments it doesn't receive any data from the calling function. Likewise, it doesn't return any

How to read datasets in multiple text files in an non interactive program?