Program to print all permutation of a string ..

program:-

#include<stdio.h>
#include<string.h>
void main()
{
void permutation(char *,int ,int);//function declaration
int length;
char str[100];
printf(“Enter the string “);
scanf(“%s”,str);
length=strlen(str);
permutation(str,0,length1);// Function calling
}
// function definition
void permutation(char *s,int i,int n)
{
static int count ;
int j;
char ch;
if(i==n)
{
count++;
printf(“%d %sn”,count,s);
}
else
{
for(j=i;j<=n;j++)
{
ch=*(s+i);
*(s+i)=*(s+j);
*(s+j)=ch;
permutation(s,i+1,n);

// Backtracting

ch=*(s+i);
*(s+i)=*(s+j);
*(s+j)=ch;
}
}
}


Leave a Reply

Your email address will not be published.