jim, you dont have to say i = 0 to 9, 0 to 8 will get the job done. 0 to 9 is NINE numbers. But your code is perfect.

also, the for loop that increments the states needs to be:

Code:
for(i=j;i>-1;i--) state[i]++;
because then it will go from j to 0 and not from j to 1.

Have fun coding...