I am stuck with this problem of trying to generate all the variations of K elements from the set [1..N]. I also had an idea that I can do that with k levels of nested loops and tried to do that recursively, but without success.
I have this function:
public static void PrintVariation(int n, int k, int[] array)
{
//when k = 2
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
Console.WriteLine("{0}, {1}", array[i], array[j]);
}
}
}
But what am I supposed to do when k
has a random value?