title: Algorithm to print all combination of letters of the given string in lexicographical order
body: <p>I tried to create the code to generate all possible combination of the given string in the lexicographical order:</p>
  
  <p>The code that I wrote is:</p>
  
  <pre><code>void get(char *n)
   {
      int l=strlen(n); 
      sort(n,n+l);
      int k=0,m,i,j,z;
  
      while(k&lt;l)
      {
          m=k;
  
          for(i=k;i&lt;l;i++)
          {
              for(j=k;j&lt;=i;j++)
                  cout&lt;&lt;n[j];
  
              cout&lt;&lt;"\n";
          }
  
          for(z=m+2;z&lt;l;z++)
              cout&lt;&lt;n[m]&lt;&lt;n[z]&lt;&lt;"\n";  
  
          k++;
      }
   }
  
  
  int main() 
   {
      char n[100];
      cin&gt;&gt;n;
      get(n);
      return 0;
   }
  </code></pre>
  
  <p>Suppose the string is : abcde</p>
  
  <p>My code is not generating combinations like:</p>
  
  <pre><code>abd
  abe
  </code></pre>
  
  <p>The output I am getting for the string abcde are:</p>
  
  <pre><code>a 
  ab
  abc 
  abcd 
  abcde 
  ac 
  ad
  ae 
  b 
  bc 
  bcd 
  bcde 
  bd 
  be 
  c 
  cd 
  cde 
  ce 
  d 
  de 
  e
  </code></pre>
  
  <p>My output does not contains strings like : <code>abd abe</code> </p>
  
  <p>Hope this makes the question clear</p>
  
  <p>How to generate all these combinations using an efficient algorithm</p>