Attention: This is absolutely not a homework
By the way, I just confused about how to solve this kind of problem.
What should I use? Iteration(I don't think so), recursive function(perhaps) or gotos
Ok, here we go.
Test case 1:
Given input:
Code:
characters: [a, b]
maximum length: 2
And the output is:
The order is unnecessary.
Test case 2:
Code:
characters: [a, b]
maximum length: 3
vvv
Code:
a aa ab b ba bb aaa aab aba abb baa bab bba bbb
Test case 3:
Code:
characters: [a, b, c]
maximum length: 2
vvv
Code:
a aa ab ac b ba bb bc
Test case 4:
Code:
characters: [a, b, c, d, e]
maximum length: 1
vvv
I tried to write a recursive function like pow and factorial
Code:
void recursive(int length, int x) {
if(x > 0) {
int i;
for(i=0; i<length; i++) {
recursive(length, x - 1);
}
}
}
Doesn't work at all
But the problem can be done using nested for loop, but as you know both of characters and maximum length are variables.
Any clue please?
Thanks in advance.