i'm having a problem with below recursive code.
there are 4 chars stored in a array, 'a', 'b', 'c', 'd'. input is between 1 and 16, and output should look like this:
when input is 1:
a
b
c
d
when iput is 2:
aa
ab
ac
ad
ba
bb
bc
bd
ca
cb
cc
cd
da
db
dc
dd
and so on...
here is the code i'v been working with:
void f(int x, int num)
{
int i;
char a[4] = {'a', 'b', 'c', 'd'};
char temp[16];
if(num == 0)
return;
else
for(i = 0; i < 4; i++)
{
temp[x] = a[i];
f(x + 1, num - 1);
temp[x + 1] = '\0';
printf("%s\n", temp);
}
}
where should i change to make it work?