hey guys, im trying to write a program recursively that takes in how many times the user wants to flip a coin, and prints out all the possibilities. i am having a hard time figuring it out. id apreciate some input. here is the code i have so far...
#include <stdio.h>
char coinflip(char* s, int size, int pos);
int main(void)
{
char* s;
int size;
int pos;
printf("How many times will you be flipping a coin?\n");
scanf("%d", &size);
s=calloc(0, sizeof(char));
coinflip(s, size, 0);
printf("%s", s);
printf("Here are all your possible outcomes:\n");
system("pause");
return 0;
}
char coinflip(char* s, int size, int pos)
{
if(size==pos)
{
return 0;
//return coinflip(s, size, pos);
}
//posibility 1
printf("H");
return coinflip("H", size, pos+1);
//posibility 2
return coinflip("T", size, pos+1);
}
it is a little bit sloppy but that is just because i was trying a bunch of different things. thanx