All Cominations of a Word

Write a C program for all possible combinations of letters in a word?

Questions by pullamma143su

Showing Answers 1 - 3 of 3 Answers

# include <stdio.h>
# include <string.h> 

void comb(char *,int,int);
void swap(char *,char *);
 
main()

{
   char s[100];
   gets(s);
   int len = strlen(s)-1;
   comb(s, 0, len);
}
 

void comb(char *s, int start, int end)
{
   int j;
   if (start == end)
     printf("%sn", s);
   else
   {
        for (j = start; j <= end; j++)
       {
          swap((s+start), (s+j));
          comb(s, start+1, end);
          swap((s+start), (s+j));
       }
   }

 

/* Function to swap values at two pointers */
void swap (char *x, char *y)
{
    char temp;
    temp = *x;
    *x = *y;
    *y = temp;
}
 

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions