There are different ways of doing it depending on whether or not you want the set of numbers sorted. One easy way of doing it is to pass an accumulator variable along with each recursive call.
Code:
void print_combinations(int n, int accumulator);
For each iteration, pass
Code:
print_combinations(n - 1, accumulator + 10^(n - 1) * i)
where i is the current number from the set of allowed numbers (use a for loop where you call print_combinations).
For example, for n=3 and the set of allowed numbers={1, 2} we get:
Code:
print_combinations(3, 0);
print_combinations(2, 100);
print_combinations(2, 200);
print_combinations(1, 110);
print_combinations(1, 120);
print_combinations(1, 210);
print_combinations(1, 220);
print_combinations(0, 111);
print_combinations(0, 112);
print_combinations(0, 121);
print_combinations(0, 122);
print_combinations(0, 211);
print_combinations(0, 212);
print_combinations(0, 221);
print_combinations(0, 222);