Proper indentation goes a long way.
Code:
void flipper(int level, char* path){
*(path+level)='A'; /* coin flip side A */
if(level==3) /* flipped coin 4 report results */
printf("%s\n",path);
else
flipper(level+1,path); /* flip next coin */
*(path+level)='B'; /* coin flip side 'B' */
if(level==3) /* flipped four coins if you want to change the number of coin tosses shange the 3 to something else both here and above*/
printf("%s\n",path); /* report the path */
else
flipper(level+1,path); /* not done flip next coin */
return;
}
Write it out on paper:
Code:
f(0)
here + 0 = A
f(1)
here + 1 = A
f(2)
here + 2 = A
f( 3 )
here + 3 = A
print string
here + 3 = B
print string
< return
here + 2 = B
f( 3 )
here + 3 = A
print string
here + 3 = B
print string
here + 2 = B
< return
I will leave the rest as an exercise to the reader.
Quzah.