Saturday, 4 June 2016

FIND PERMUTATION IN A GIVEN STRING:
A permutation, also called an “arrangement number” or “order,” is a rearrangement of the elements of an ordered list S into a one-to-one correspondence with S itself. A string of length n has n!permutation.
Source code:
#include <stdio.h>
#include<string.h>
void swap(char *x,char *y)
 {
  char temp;
  temp=*x;
  *x=*y;
  *y=temp;
}
void permute(char *a,int l,int r)
{
  int i=0;
  if(l==r)
{
    printf("%s\n",a);
}
  else
    {
      for(i=l;i<=r;i++)
       {
        swap((a+l),(a+i));
        permute(a,l+1,r);
        swap((a+l),(a+i));
       }
     }
}
int main(void) {
    // your code goes here
    char str[100];
    scanf("%s",str);
    int n=strlen(str);
    permute(str,0,n-1);
    }

 Input and output: