how to write a program that do this ? i need help please
{2*f(n-3) +f(n-2)+f(n-1) x>1}
{1 x=<1}
A. A: What is the result of this function for 6? Draw the tree recursive process generated in computing (g (6)).
B. B: write a recursion function for this function.
I assume that in your description:
f(n) is equal to your funny brackets;
'x' actually means 'n';
g(6) actually means f(6);
You should write a function
1 2 3 4
int f( int n )
{
//
}
Inside your function you have an if-else structure so that if n is <= 1 you return 1 and if not you return 2*f(n-3) +f(n-2)+f(n-1). (These are the recursive function calls - just code them like that and let the computer take care of them.)
Apart from initially calling this function from main() that's about it.
Well, you just have to adjust your return type according to the data that comes through. Try to solve it by hand first and see how would you approach it then translate that into code.
Here's an example of a branched pure recursive function to help you out. As you see, it returns a different thing according to its arguments.
1 2 3 4 5 6
int f_ack(int n, int m)
{
if(m==0) return n+1;
elseif(m>0 and n==0) return f_ack(m-1,1);
elseif(m>0 and n>0) return f_ack(m-1, f_ack(m,n-1));
}