/* a program to find all the permutations of an input string
pointers are not allowed*/
#include <stdio.h>
#include <string.h>
#include <conio.h>
void main()
{
clrscr();
int num =0;
char buff[20] ;
printf("Enter the string\n");
scanf("%s",buff);
int len = strlen(buff);
printf("%s\n",buff);
for(int i=0;i<len;i++)
{
for(int j=1;j<len;j++)
{
for(int k=j+1;k<len;k++)
{
char x = buff[j];
char y = buff[k];
if(x != y)
{
char tmp[10];
for(int tem=0;tem<len;tem++)
{
tmp[tem] = buff[tem];
}
tmp[j] = y;
tmp[k] = x;
tmp[len] = '\0';
printf("%s\n",tmp);
}
}
}
if(i+1 < len)
{
char x = buff[0];
char y = buff[i+1];
if(x != y)
{
buff[0] = y;
buff[i+1] = x;
printf("%s\n",buff);
}
}
}
getch();
}
/*this works for strings upto 3 characters.but more than 3,all permutns r not printed*/