Question: Implement a recursive function called binomial() to compute the binomial coefficient according to the following mathematical definition: If k This is what I have so

Implement a recursive function called binomial() to compute the binomial coefficient according to the following mathematical definition:

Implement a recursive function called binomial() to compute the binomial coefficient according

If k

This is what I have so far. Ive been working on this all week and cannot get it to work.

#include

#include

#include

using namespace std;

int binomial(int n, int k);

int main(int argc, char **argv)

{cout

cout

cout

cout

cout

cout

cout

cout

cout

cout

cout

getchar();

return 0;

}

int binomial(int n, int k)

{ if (k == 0 || k == n)

{return 1;}

else

{return binomial(n - 1, k - 1) + binomial(n + 1, k);}

}

Hint: The variables enclosed in parenthesis provided in the mathematical definition are calls to the binomial() function.

Output: Once the function is implemented, the output for the program should appear as follows. Note that the error messages do not have to appear exactly as show, but the return results from the function must match.

binomial(95, 4)=3183545

binomial(24, 0)=1

binomial(38, 5)=501942

Error: n or k cannot be less than 0. [n=40,k=-5]

binomial(41, -5)=-1

Error: k cannot be greater than n. [n=89,k=120]

binomial(90, 120)=-2

Error: n or k cannot be less than 0. [n=-78,k=2] 2

binomial(-77, 2)=-1

binomial(47, 47)=1

binomial(18, 1)=18

binomial(51, 0)=1

Error: k cannot be greater than n. [n=27,k=32]

binomial(28, 32)=-2

Press any key to continue.

f k = 0 or k = n otherwise

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!