C program for generating combination

Respected members,

I am new student of programming and currently learning C. I have an assignment of generating all possible combinations of n elements out of K numbers. After searching lot on google, I got following code using nested for loop. But its not working for me. Please help me.

Code:

`int a = 0;`

int b = 0;

int c = 0;

int d = 0;

int k[10]={1,2,3,4,5,6,7,8,9,10};

int n = 4;

int main()

{

for (a = 0; a <= n - 3; ++a)

{

for (b = a+1; b <= n-2; b++)

{

for (c = b+1; c <= n-1; c++)

{

for (d = c+1; d <= n; d++)

{

printf("%d,%d,%d,%d", k[a],k[b],k[c],k[d];

}

}

}

}

}