Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(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 , , or )

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 11g SQL

Authors: Jason Price

1st Edition

0071498508, 978-0071498500

More Books

Students also viewed these Databases questions

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago