View Feed
group-icon
Coffee Room
Discuss anything here - everything that you wish to discuss with fellow engineers.
12920 Members
Join this group to post and comment.

Combinations of characters

Can someone give me a code that works as follows:

Input :
A word containing at max 10 letters.eg: "team"

Output:
The program should print the different words that can be formed using these letters.
eg:team,tema,taem,tame,tmae,tmea, and so on. So the 4 letters give 4! that is 24 words.

I am stuck up badly as I cant get any idea.Please someone help.😕
Prasad Ajinkya
Prasad Ajinkya • Nov 21, 2008
Ashutosh,
Here's a hint - Use recursion or while loop.

You need to -
1. first divide the string into an array of characters ... so "team" becomes 't','e','a','m'
2. Then just make a recursive function to output the letter

Get it?
Thanks your advice worked.I got some weird looking code but it worked in some cases.Can you please check it out.
#include
#include
#include
char str[10];
static int index[10];
int len;
int count=0;
void anagram()
{
 if(count==len-1)
 {
  int p,q,flag;
  index[count]=0;
  for(;index[count]>str;
 len=strlen(str);
 cout<<"\nThe anagrams found are as follows : \n";
 cout<<"Press enter to get next anagram : \n";
 anagram();
 getch();
}
😁

Share this content on your social channels -