(in c++, without using #include <iostream.h>, <stdio.h>, <assert.h> or <conio.h>
ID: 3676200 • Letter: #
Question
(in c++, without using #include <iostream.h>, <stdio.h>, <assert.h> or <conio.h>)
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:
Explanation / Answer
Output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.