The formula for computing the number of ways of choosing r different things from
ID: 662795 • Letter: T
Question
The formula for computing the number of ways of choosing r different things from a set of n things is the following:
C(n, r) = n! / (r! (n r)!)
The factorial function n! is defined by
n! = n (n 1) (n 2) ... 1
Discover a recursive version of this formula and write a recursive function that computes the value of the formula. Using this recursive function, write a function which computes the formula for number of ways to choose r different things from a set of n things.
Then write a program that takes r and n as user input, then calls the above functions and outputs the result.
Hint: some of the intermediate values (such as 16!) are too large to fit in a variable of int type. Consider using a type which can store larger numbers such as long (or even unsigned long, since our numbers are all positive in this problem).
The program should print a string of text to the terminal before getting each line of input from the user. A session should look like the following example (including whitespace and formatting), with possibly different numbers in the output:
The strings printed by the program should include a newline at the end, but no other trailing whitespace (whitespace at the end of the line).
Explanation / Answer
Now to consider the combination part of the code i.e C(n, r) = n! / (r!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.