Question

IN C++ The Catalan numbers are an integer sequence Cn that appears in tree-enumeration problems. The...

IN C++

The Catalan numbers are an integer sequence Cn that appears in tree-enumeration problems. The first Catalan numbers for n = 1, 2, 3, ... are 1, 2, 5, 14, 42, 132, .... A formula generating Cn is:

Cn=(1÷(n+1))=(2n)!÷(n+1)!n!

Design two programs that communicate with shared memory using the Win32 API as outlined in Section 8.7.2. The producer process will generate the Catalan sequence and write it to a shared memory object. The consumer process will then read and output the sequence from shared memory.   

In this instance, the producer process will be passed an integer parameter on the command line specifying how many Catalan numbers to produce (for example, providing 5 on the command line means the producer process will generate the first five Catalan numbers).

Homework Answers

Answer #1

Code in C++:

#include<iostream>
using namespace std;
int catalan(int n)
{
if(n<=1)
{
return 1;
}
  
int result=0;
for(int i=0;i<n;i++)
{
result = result+catalan(i)*catalan(n-i-1);
}
return result;
}

int main()
{
int n;
cout<<"enter the value of n:";
cin>>n;
cout<<"C["<<n<<"] =" <<catalan(n)<<endl;
return 0;
}

For any doubts, you can comment.down below.

I will be ready to answer your queries

Stay safe and be fit :)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT