To print all combinations for the given string

This program can print all combinations for the given string.
Logic:
- Get the input string from the user.
- Swap the kth element with the (k-1)th element.
- Swapping process continues up to index 0.
- Repeat step 2 and 3 for n times.
- Then Print all combinations of strings.
Program:
[code lang=”c”]
#include<stdio.h>
void main()
{
char a[20];
int i,j,n,k,temp;
clrscr();
printf("enter the string:");
gets(a);
n=strlen(a); //finds the length of the string
for(j=0;j<n;j++)
{
for(k=n-1;k>0;k–) //swap the kth index with (k-1)th upto the index 1
{
temp=a[k];
a[k]=a[k-1];
a[k-1]=temp;
printf("%s\n",a); //print after swapping
}
}
getch();
}
[/code]