1. This question concerns a recursive function i have to write. its basically has to take a number in that will represent the the number of times you flip a coin. I need a way to print out all possible solutions.

So for example say the user puts in 1, the output would be ' HT '.
input is 2 so it prints hh tt th ht etc.

What it does is takes in a number from the user and outputs the possible

so far ive come up with
Code:
```int coin(int x)
{

if(x==0)
return;

else
{
return coin(x-1);

}```
QUESTION NOW IS:

How would i print out the possible solutions. I was thinking something like strcat adding the letters but im not really sure how to proceed from where i am?

2. I would suggest with, say, two coin flips and three coin flips. Look for patterns -- especially ways to use the two-coin-flip answers inside the three-coin-flip problem (since that's what recursion does, go down one level).

3. Originally Posted by tabstop
I would suggest with, say, two coin flips and three coin flips. Look for patterns -- especially ways to use the two-coin-flip answers inside the three-coin-flip problem (since that's what recursion does, go down one level).
ok. well correct me if i am wrong as i am just a begining comp science. student. I was informed that i had to do a double recursive call for this to even work period. I dont know if it makes sense at all. On the other hand how would i even go about coding something like this.

4. Originally Posted by sumdude
I was informed that i had to do a double recursive call for this to even work period.
If you mean your function will call function(n-1) twice, then yes. Most coins do have two sides.
Originally Posted by sumdude
I dont know if it makes sense at all. On the other hand how would i even go about coding something like this.
That's why you start with paper. Write out the possibilities for two coins and three coins and look at the patterns.

5. ok will try that out. appreciate the help

6. This is what i came up with but it only prints the h's. any help?

int flip(int x, char string[])
{

if(x==0)
{ printf("&#37;s\n", string);
return 0; }

if(x>0)

{

return flip(x-1,strcat(string,"H"));
return flip(x-1,strcat(string,"T"));

}

}
Can someone tell me where im going wrong please/

7. Once you hit return, that's it. There's no way to get to the line "return flip(x-1, strcat(string, "T"));" in this function.

8. Originally Posted by tabstop
Once you hit return, that's it. There's no way to get to the line "return flip(x-1, strcat(string, "T"));" in this function.
so how can i resolve this problem?

9. Don't return.

Just call the function.

10. ok here is what im getting

2
HTHH
HTHHT
HTHHTTH
HTHHTTHT

why is this happen. Also i did declare in main ..... char sting[50]="HT"

11. Originally Posted by sumdude
char sting[50]="HT"
So don't do that. string must be empty when this function is first called.

And as you can see, things are not getting removed when you go from the H call to the T call. I'm guessing you want to make two local copies of the string (one to be passed into the H call, one to be passed into the T call) so that they don't interfere with each other in this way.

12. still cant get this ting to work. now its begining to print out some wierd characters.