Question: HELP WITH C++ HOMEWORK Create a program that uses a function to compute the binomial coefficients (the number of combinations k items that can be

HELP WITH C++ HOMEWORK

Create a program that uses a function to compute the binomial coefficients (the number of combinations k items that can be selected from a set of n items.)

The binomial coefficient is defined as:

n/k = C(n,k) = n!/k!(n-k)! for n and k satisfying : 0 < or equal k < or equal n

- If n < 0, k < 0 or K > n the binomial coefficient is considered to be zero.

(Both n and k are integer numbers)

- Also, 0/0 = 1 the one example where the recursion relation does not hold.

Prompt the user for the input values of n and k respectively.

Create a function named factorial that will compute the factorial of a number.

3. Create a function named binomial to compute the binomial coefficients using the inputs entered by the user. You must use the factorial function defined from part 2.

4. Create a function named output to print the binomial coefficients or an error message to the screen.

5. The output should look like the one of following:

The binomial coefficient C(7, 3) = 35

The binomial coefficient C(3, 7) = 0 (Invalid parameters)

The binomial coefficient C(4,-1) = 0 (Invalid parameters)

6. Test your program with the following inputs of n and k.

(12,3), (3,4), (4,-2), (-4,7), (13,0)

Expected output for each of the values required:

(12, 3): BC = 220

(3, 4): BC = 0, Invalid

(4, -2): BC = 0, Invalid

(-4, 7): BC = 0, Invalid

(13, 0): BC = 1

----------------------------------------------------------------------------------------------------------------------------------------------

what I have so far ( I don`t know if my function factorial is correct, so fix if it is necessary)

#include

#include

#include

using namespace std;

int factoria (int n);

int binomial (int n, int k);

int output (binomial);

int main()

{

int n;

int k;

cout << "Enter a positive number for n: ";

cin >> n;

cout << "Enter a positive number for k that is smaller or equal n: ";

cin >> k;

return 0;

}

int factorial (int n)

{

if (n == 1)

return n;

else

return n * factorial (n-1);

}

int binomial (int n, int k)

{

}

int output (binomial)

{

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!