S
sophia
Dear all,
The following is the program which i have done to find all the
combination of letters in the string "hello"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 5
int main(void)
{
char t[MAX];
int i,j,k,l,m,n=1;
strcpy(t,"hello");
printf("\n words formed from the combinations of all characters
from \
the word hello\n\n");
for(i = 0 ;i < MAX ;i++)
for(j = 0 ;j < MAX ;j++)
{
if(j == i)
continue;
for(k = 0 ;k < MAX ;k++)
{
if( (k==i) || (k == j) )
continue;
for(l = 0 ;l < MAX ;l++)
{
if( (l==i) || (l == j) || (l == k) )
continue;
m = 10 - (i + j + k + l);
printf("%c%c%c%c%c ",t,t[j],t[k],t[l],t[m]);
if(n %10 == 0) puts("");
n++;
}
}
}
printf("\n no: of words formed = %d",--n);
puts("");
return EXIT_SUCCESS;
}
can any one suggest a more general method so that i can find the
combination of letters of any inputted string ?
The following is the program which i have done to find all the
combination of letters in the string "hello"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 5
int main(void)
{
char t[MAX];
int i,j,k,l,m,n=1;
strcpy(t,"hello");
printf("\n words formed from the combinations of all characters
from \
the word hello\n\n");
for(i = 0 ;i < MAX ;i++)
for(j = 0 ;j < MAX ;j++)
{
if(j == i)
continue;
for(k = 0 ;k < MAX ;k++)
{
if( (k==i) || (k == j) )
continue;
for(l = 0 ;l < MAX ;l++)
{
if( (l==i) || (l == j) || (l == k) )
continue;
m = 10 - (i + j + k + l);
printf("%c%c%c%c%c ",t,t[j],t[k],t[l],t[m]);
if(n %10 == 0) puts("");
n++;
}
}
}
printf("\n no: of words formed = %d",--n);
puts("");
return EXIT_SUCCESS;
}
can any one suggest a more general method so that i can find the
combination of letters of any inputted string ?