can any one give code for this problem

For the input word and a number, print all possible combinations that have as many characters as specified by the number. For example, CAT 2 would produce CA, CT, AT and DOG 1 would produce D, O ,G .Note, that we are producing combinations WITHOUT replacement, so in the CAT 2 example, CC , AA and TT are NOT possible combinations.

Input

Accept a line of input entered from standard input. A valid line contains a word and a number. The word comes first, and is up to twenty characters. The word may be preceeded and followed by any number of blanks. The number is a decimal integer greater than zero, and may be followed by any number of blanks or a return.
Output

The output is the list of subwords, one word per line, left justified. The program should respond to invalid input by issuing a one line message indicating the nature of the error:
“Number greater than length of word”
“Word longer than 20 characters”
Example

Input:
CAT 2

Output:
CA
CT
AT

It smells like “do my homework” to me, but anyway…

What you tried already?

1 Like