I would split this up into two problems: a) find all the combinations nCk of your array of size n b) find all the permutations of an array of length k. You said you already know how to do the permutations, so let's focus on the combinations:
void combinations(int *arr, int *comb, int n, int k, int kCurr)
{
if(kCurr >= k)
{
permutations(comb, k);
return;
}
int i;
for(i=0; i<n; ++i)
{
comb[kCurr] = arr[i];
combinations(arr+i, comb, n-i, k, kCurr+1);
}
}
which would be called like this:
int myArray[49] = {1, 2, ..., 49};
int myCombs[5];
combinations(myArray, myCombs, 49, 5, 0);
This computes all the combinations 49C5 by building up the array myCombs
, and when it is full it calls a function permutations
. If permutations
is implemented properly then you will print out all permutations of all combinations of 49C5.
EDIT: Duh, you can just do combinations(arr, comb, n, k kCurr+1)
as the recursive step, and then just print the array in the base case (or do whatever).