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.😕

Replies

  • Prasad Ajinkya
    Prasad Ajinkya
    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?
  • Ashutosh_shukla
    Ashutosh_shukla
    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();
    }
    
    😁

You are reading an archived discussion.

Related Posts

wat kind of the authentictaion does the My Sql server provides to the users
Hi Everybody, This is Ruhi Jain from HCLTECH(Gurgaon). I always wanted to join a forum/site that make me proud of my Engineering. Something that's crazy n exclusively for Engineers. It...
heyyyy i m final year mechanical engg. student cn nyone help in suggestin me a good project it wud be better if it is a workin one
CEans, CE announces its CE Ambassadors Team comprising of following selected CEans :- CEan - durga CEan - Differential CEan - sauravgoswami Many congratulations to selected CEans. Discuss this announcement...
This is hemanth. Studying 2nd b-tech in ECE streem. I am thinking to give a presentation regarding to electronics. Will some one help me out in choosing a apropriate topic...