Dear Members,

If you can help me, I will be greatly thankful,

I want to write an algorithm to do the following:
Input: two positive integers N,K
The output should be an array whose number of columns is N,
and its rows lists all the possible combinations of natural integers less than or equal K (possibly zero) such that the sum of every row is K.

To clerify more, Let N=3, K=2
the output array is
2 0 0
1 1 0
1 0 1
0 2 0
0 0 2
0 1 1

Notice that the sum of every row = K=2

Another example, N=4,K=3

3 0 0 0
2 1 0 0
2 0 1 0
2 0 0 1
1 2 0 0
1 1 1 0
1 1 0 1
1 0 2 0
1 0 1 1
1 0 0 2
0 3 0 0
0 2 1 0
0 2 0 1
0 1 2 0
0 1 1 1
0 1 0 2
0 0 3 0
0 0 2 1
0 0 1 2
0 0 0 3




Thanks,