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
How and where to start to develop a preprocessor for java

Problem Solving 1. Write Pascal code that accepts as input the names of the students, course work score and exam score for a unspecified number of students who have taken a subjec

You are to write a program which will answer a pair of questions for squares, triangles, circles and ellipses. A square is defined by its lower left corner (SLLx,SLLy), and the len

Note: You should pay attention on following good practices: Appropriate code comments(If you make any assumptions clearly comment them in the code) Indentation

Question 1 Discuss on UNIX kernel components 2 Explain process creation and process termination 3 When do a Deadlock occur? What are the Necessary Conditions for Deadlock

Consider the following schema (DTD) and sample instance document: name    ID      #REQUIRED spouse  IDREF   #IMPLIED job     CDATA   #IMPLIED > ]>

list of 10 operating systems with their hardware specification and also list any 5 software associated with each operating system

Define the Syntax of FOR Loop? The universal form of this statement is for(initialization;condition;increment/decrement)             { statements;             }

I''m doing a project for class in college and im supposed to use today''s date and figure out how old i am in months, days, minutes, and seconds. My question is what is the beset

Question: (a) Outline the six norms to be considered before designing a Web page. (b) Write a program such that when a user right-clicks anywhere on a Web page, the follow