Question
(in c++, without using #include , , or ) The formula for computing the number of ways of choosing r different things from a set
(in c++, without using #include
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:
Enter r (number of things to choose): 3 Enter n (the number of things to choose from): 6 There are 20 ways to choose 3 things from a set of 6 things. 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). Also take care of singular and plural words in the sentence (1 way, 2 things etc.)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started