Finding all the permutations for any given set of items has always been an area of interest for programmers. A very simple algorithm for finding all the permutations, the Bell Algorithm and its C coding has already been presented.

Here the recursive code in C, for finding all the possible permutations has been given :
#include “stdio.h”
#include “conio.h”
char a[7]={‘a’,'b’,'c’,'d’,'e’,'f’,'g’};
int n=3;
main()
{
int i;
for(i=1;i<=n;i++)
comb(0,i);
}
comb(int index,int number)
{
int i;
char t;
if(index==number) {
for(i=0;i<number;i++)
printf(“%c”,a[i]);
printf(“\n”);
}
else{
for(i=index;i<n;i++)
{
t=a[i];
a[i]=a[index];
a[index]=t;
comb(index+1,number);
a[index]=a[i];
a[i]=t;
}
}
}

Posted in
Tags: 

Thank you for upload the source code.
======================================
#include
char a[7]={‘a’,'b’,'c’,'d’,'e’,'f’,'g’};
int n=3;
void comb(int index,int number);
int main(void)
{
int i;
for(i=1;i<=n;i++){
comb(0,i);
}
return 0;
}
void comb(int index,int number)
{
int i;
char t;
if(index==number) {
for(i=0;i<number;i++)
printf("%c",a[i]);
printf("\n");
}
else{
for(i=index;i<n;i++)
{
t=a[i];
a[i]=a[index];
a[index]=t;
comb(index+1,number);
a[index]=a[i];
a[i]=t;
}
}
}
======================================
Save the source and compile it without error and warning.
#include
char a[7]={‘a’,’b’,’c’,’d’,’e’,’f’,’g’};
……