title: C program to print combination of 3 letter word
body: <p>I want to print the combination of any 3 letters without using nested for loop in C programming ?</p>
  
  <p>Following is the code for the combination of 3 letters "ABC". 
  I can execute the program by using 3 for loops. 
  But I dont want that. I want to do it by only one for loop and in a non-recursive way.But I am not getting any logic.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main()
  {
  
      int i=0,j=0;
      char b[10],a[] = "ABC";
      strcpy(b,a);
      while(i &lt; 3)
      {
          b[j]=a[i];
  
          if(i==0)
          {
              b[j+1]=a[i+1];
              b[j+2]=a[i+2];
              printf("\n%s",b);
  
              b[j+1]=a[i+2];
              b[j+2]=a[i+1];
              printf("\n%s",b);
  
          }else if(i==1)
          {
              b[j+1]=a[i+1];
              b[j+2]=a[i-1];
              printf("\n%s",b);
  
              b[j+1]=a[i-1];
              b[j+2]=a[i+1];
              printf("\n%s",b);
  
          }else
          {
              b[j+1]=a[i-1];
              b[j+2]=a[i-2];
              printf("\n%s",b);
  
              b[j+1]=a[i-2];
              b[j+2]=a[i-1];
              printf("\n%s",b);
          }
  
          i++;
  
      }
  
      getch();
      return 0;
  }
  </code></pre>