Auto AdSense

Tuesday, 13 August 2013

C Program to perform 4-letter WORD UNSCRAMBLING

/*
        List all possible combinations of 4-letters in a word.
        Ex: The word 'TEST' can be unscrambled as TEST,TETS,TSET,TSTE,TTSE,TTES,etc.  
                                                                                                                                             */


/* 4-letter word unscrambling */

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i,j,k,l,sum=6;
char *str;
clrscr();
printf("Enter a 4-letter word or string : ");
scanf("%s",str);
if (strlen(str) == 4)
{
printf("The possible combinations of the given 4-letter word is shown.");
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++)
   if (i != j)
{
   for (k = 0; k < 4; k++)
if ((k != i) && (k != j))
{
   l = sum - (i + j + k);
   printf("\n%c%c%c%c",str[i],str[j],str[k],str[l]);
}
}
printf("\nTotal combinations = %d",4*3*2*1);
}
else
printf("\nInvalid string. Length of the string must be 4-letters only ");
getch();
}

No comments:

Post a Comment