Shell script for combinations ncr, Programming Languages

Assignment Help:

 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


Related Discussions:- Shell script for combinations ncr

Game programming, Companies divide their subtasks of game's development. Fo...

Companies divide their subtasks of game's development. For large complex games, the development team can vary in size from 20 to 100 or more members. The most represented are artis

Oop, Using OOP,write a sample program to get the factorial of a number ente...

Using OOP,write a sample program to get the factorial of a number entered by a user

Explain the post and get methods, Question: (a)  An HTML file "decor.ht...

Question: (a)  An HTML file "decor.html" uses an external Cascading Style Sheet file name  "nicedesign.css". Users are viewing the Web page making use of different kinds of  br

Matlab, ,how to write matlab program for fast decoupled method

,how to write matlab program for fast decoupled method

Java program, Write a java program for inserting a particular node.

Write a java program for inserting a particular node.

Sizes of the clusters influence-k-means program, Objective: to show if th...

Objective: to show if the sizes of the clusters influence the communication cost among a set on nodes Write a K-Means  program  for a set of M points randomly distributed on an

Shell script to find a particular pattern from the file, Normal 0 ...

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

Program for tube challenge route, 1. Introduction The Tube Challenge is ...

1. Introduction The Tube Challenge is a Guinness World Records challenge that tests both the physical and mental abilities of the person trying to break it. The main components

List recursion to de ne the function, Use list recursion to de ne the funct...

Use list recursion to de ne the function mySum which takes as input an integer and a list of integers and returns the list obtained by adding every element of the list by the rst

Lunix, showing work Ubuntu system or either opensuse

showing work Ubuntu system or either opensuse

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd