DoubleOseven DoubleOseven - 1 year ago 108
C++ Question

Recursive c++ function

I am trying to create a recursive function as follows.

The function takes a counter

and as long that the counter is larger than zero I would like to call it recursively so that in the end I end up with something like this:

result = 2(2(2n+1)+1)+1

where the last n (when k=0) should be zero.

int pass(int k, int n)
n = 0;
return pass(k, 2*n+1);

Can someone give me a hint as on how to do it?

Answer Source


n = 0;


return n;

To return the result.

The rest of the code is fine

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download