Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

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

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

Step: 3

blur-text-image

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

Spatial Databases A Tour

Authors: Shashi Shekhar, Sanjay Chawla

1st Edition

0130174807, 978-0130174802

More Books

Students also viewed these Databases questions

Question

/ etc / passwd file flag 5

Answered: 1 week ago