Let's say you want to print combinations of a,b,c,d,e which are {a,b,c} {a,b,d} {a,b,e} {a,c,d} {a,c,e} {a,d,e} {b,c,d} {b,c,e} {b,d,e} {c,d,e}
Let's generalize it a little, for an N,3 combination. For a combination, the order of elements in a term is not important ({a,b,c} is the same as {c,a,b}), but two elements cannot be repeated. So for simplicity, it is easier to arrange them in alphabetical order
You need to do the following steps:
1. initialize an array char letters[N] with letters[0]='a' and so on
2. loop over the first element of your output. Your index will go from 0 to N3. Why N3? because if I would have N2 the second element must be letters[N1] (alphabetically increasing) and the third would be letters[N]  out of bounds
3. loop over the second element of your output. Using the same reasoning, you start from the index of the first element + 1, and go up to N2
4. loop over the third element of your output. This will start from the index of the second element, and will end at N1
5. Print the combination
1 2 3 4

for(int i=0; i<N3; i++)
for(int j=i+1; j<N2; j++)
for(int k=j+1; k<N1; k++)
cout<<"{"<<letters[i]<<","<<letters[j]<<","<<letters[k]<<"}\n";
 
Obviously printing N,p combinations in general would be a little more complicated, but still doable. See
http://stackoverflow.com/questions/12991758/creatingallpossiblekcombinationsofnitemsinc