Write Permutations. Read a word and a limit. Generate all distinct permutations of its letters in alphabetical order with a recursive method that fills one position at a time using a used[] array; print the first limit of them, ... (k more) if there are more, and the total.
Repeated letters must not produce repeated results (aab has 3 permutations, not 6): sort the letters first, and skip a letter equal to its left neighbour when that neighbour is not currently used.
For the input
abc 10
the program prints
abc
acb
bac
bca
cab
cba
Distinct permutations: 6