#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 100
void swap(char array[MAX])
{
int l_indx=strlen(array)-1;
char t=array[l_indx];
array[l_indx]=array[l_indx-1];
array[l_indx-1]=t;
}
void shift(char array[MAX],int size)
{
int idx=strlen(array)-size;
char t=array[idx];
while(idx<strlen(array)-1)
{
array[idx]=array[idx+1];
idx++;
}
array[idx]=t;
}
void permutations(char array[MAX],int size)
{
if(size<=1)
printf("%s",array);
else if(size==2)
{
printf("%s\n",array);
swap(array);
printf("%s\n",array);
swap(array);
}
else
{
int i=0;
while(i<size)
{
permutations(array,size-1);
shift(array,size);
i++;
}
}
}
int main()
{
char str[MAX];
printf("Enter a string to get the permutation of elements\n");
scanf("%s",str);
printf("*******************\n");
permutations(str,strlen(str));
system("pause");
return 0;
}
0 comments:
Post a Comment