 |
|
 |
Home : C/C++
Name : RotRec
Description : This C program will ask for a string as an input and will print all possible combination of that string. For example if you give \"abc\" as an input, it will print abc,acb,bca,bac,cba,cab as the output.
Code :void rotate(char *c,int start)
{
int x=strlen(c)-start-1;
char temp=c[start];
while(x-->0)
c[start++]=c[start+1];
c[start]=temp;
}
void rotrec(int start,int lenth,char *c)
{
int i=0;
if(lenth==0)
printf(\"\\n%s\",c);
else
{
while(i++<lenth)
{
rotrec(start+1,lenth-1,c);
rotate(c,start);
}
}
}
main()
{
char *s;
int lenth;
printf(\"Enter the maximum string lenth : \");
scanf(\"%d\",&lenth);
s=(char *)calloc(lenth,sizeof(char));
printf(\"Enter the string : \");
scanf(\"%s\",s);
lenth=strlen(s);
rotrec(0,lenth,s);
getch();
}
|
|
 |