#include <stdio.h>
#include <stdlib.h>
#include<string.h>
char combine(char [],int k,int n);
int main()
{
char str[10];
int m,n;
printf("enter the string: ");
fgets(str,sizeof(str),stdin);
m=0;
n=strlen(str);
printf("the combinations are....\n");
combine(str,m,n-1);
return 0;
}
char combine(char a[],int k,int n)
{
int i;
char temp[40],t;
strcpy(temp,a);
if(k==n)
{
printf("%s\t",a);
}
else{
for(i=k;i<=n;i++)
{
t=a[k];
a[k]=a[i];
a[i]=t;
combine(a,k+1,n);
}
}
strcpy(a,temp);
}
actually output will be like this
enter the string:ab
the occurences are
1.aa
2.bb
3.ab
4.ba