#include
#include
void permute(char *,int,int);
void main()
{
char str[20];
int l;
clrscr();
printf("Enter the string:");
scanf("%s",str);
l=strlen(str);
printf("\nPermutations of the letters of the string:");
printf("\n------------------------------------------");
permute(str,0,l);
printf("\n------------------------------------------");
getch();
}
void permute(char *n,int start,int len)
{
int i,j;
char temp;
for(i=start;i
for(j=i+1;j
temp=n[i];
n[i]=n[j];
n[j]=temp;
permute(n,i+1,len);
temp=n[i];
n[i]=n[j];
n[j]=temp;
}
}
printf("\n%s",n);
}
No comments:
Post a Comment