#include<stdio.h>
#include<string.h>
int main()
{
void permute(char[],char[],int[],int,int);
char A[100];
scanf("%s",A);
char B[100]="";
int length=strlen(A);
int level=0;
int used[100]={0};
permute(A,B,used,length,level);
return 0;
}
void permute(char* A,char* B,int* used,int length,int level)
{
if(level==length)
{
B[level]='';
printf("%s\n",B);
return;
}
else
{
for(int i=0;i<length;i++)
{
if(used[i]==1)
{
continue;
}
used[i]=1;
B[level]=A[i];
permute(A,B,used,length,level+1);
used[i]=0;
B[level]='';
}
return;
}
}
A blog on programming and software design interview problems and solutions. Also there are some application development related stuff.
Pages
Sunday, July 22, 2012
C Program to write the permutations of the characters of a string using Recursion
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment