Thursday, July 30, 2009

A C program that can generate all possible words from a given set of letters.?

Example: Given the word "abc", your program should - by exploring all different combination of the three letters - output the words "abc", "acb", "bac", "bca", "cab" and "cba".


In the word taken from the user, some letters may appear more than once. For a given word, your program should not produce the same word more than once, and the words should be output in alphabetically ascending order

A C program that can generate all possible words from a given set of letters.?
char test[]={'a','b','c'};


for(int i=0;i%26lt;3;i++) {


for(int j=0;j %26lt; 3; j++) {


for (int k=0;k%26lt;3;k++) {


if((i!j)%26amp;(i!k)%26amp;(j!k)) {


printf("%c%c%c\n",test[i],test[j],test...


}


}


}


}
Reply:I want to help you, but I think it will takes me 15-30minutes to did that. I will give you a tip:


That program should use malloc() function to dynamically set memory location for each character inputted by the user to be manipulated.


malloc() function assures you the best way to do it.


No comments:

Post a Comment