Here is my code guys. I don't know how to fix the repetitions. Pls help.
CODE
#include <stdio.h>
#include <string.h>
/*Calculate Factorial*/
long factorial( int limit )
{
if ( limit == 0 )
return 1;
else
return(limit * factorial ( limit - 1 ));
}
/*Print Permutations*/
void permutations (char string[], int limit)
{
int idx, looper,const_idx;
char temp;
char copy[256];
strcpy(copy, string);
for(const_idx=0, idx = 1, looper = 0; looper < limit; looper++, idx++)
{
if(idx == strlen(string))
idx = 1;
/*Shuffle String*/
temp = string[const_idx];
string[const_idx] = string[idx];
string[idx] = temp;
printf("\n%s",string);
}
}
int main()
{
int limit, NofLetters;
char string[15];
printf("Enter string here: ");
gets(string);
NofLetters = strlen(string);
limit = factorial(NofLetters);
permutations( string , limit );/*pass string and limit */
getch();
return 0;
}