English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

4 answers

For writing such a program in C, it would have been more appropriate to restrict it to only meaningful arrangements.

2006-10-22 21:12:40 · answer #1 · answered by mkm 2 · 0 0

1)obtain the num of character....
2)use swapping to generate permutation and then store it in a stack.
3)print the character array by traversing the stack

2006-10-23 07:46:11 · answer #2 · answered by jonam 2 · 0 0

hi.you should save your word in an array.and then countinue like this:
1-you keep the frist aghabet and move it in your word,
2- move the second alghabet in your word
3-continue up to the end.
but this is not the best way. you have to ghange it abit.

2006-10-23 04:16:49 · answer #3 · answered by rebeka646 1 · 0 0

I believe this program does generate all possible arrangements. It could be optimized some, but it gets the job done.

Good luck.

#include "stdafx.h"
#include
#include
#include

char wordList[10000] = "";

void process (char* word, char* word1, char* word3)
{
char save;
char word2[10];
char fullWord[10];

for (int i = 0; i < strlen (word1); i++)
{
strcpy_s (fullWord, word3);
strncat_s (fullWord, word, 1);
strncpy_s (word2, word1+1, strlen(word1)-1);
process (word1, word2, fullWord);

save = word1[0];
word1[0] = word1[i+1];
word1[i+1] = save;
}
if (strlen (word) == 1)
{
strcat_s (wordList, word3);
strcat_s (wordList, word);
strcat_s (wordList, "\n");
}
}


int _tmain(int argc, _TCHAR* argv[])
{
char orig[10] = "123";
char word[10];
char word1[10];
char dmmy[10] = "";
char save;

strcpy (word, orig);
strcpy (word1, orig);

for (int i = 0; i < strlen (word); i++)
{
strncpy_s (word1, word+1, strlen(word)-1);
process (word, word1, dmmy);
strcpy_s (word, orig);
save = word[0];
word[0] = word[i+1];
word[i+1] = save;
}
printf (wordList);
printf ("\n");
return 1;
}

2006-10-24 08:49:51 · answer #4 · answered by Duane 1 · 0 0

fedest.com, questions and answers