Display different combinations of some letters forming a word

W.a.p in C to input a word. find the total no. of letters forming the word. and using these letters display the total no. of possible combinations without repeating any letter.

for example:

if string entered is "sunil", the total no. of letters in the word is 5 i.e. s,u,n,i,l.
and then displays
sunil
sunli
suinl
suiln
sulin
sulni ............. like this

again if string entered is "dipi", the total no. of letters forming the word is 3 i.e. d,i,p and displays
dip
pid
idp
dpi
pdi
ipd

Questions by mailmeskb

Showing Answers 1 - 3 of 3 Answers

amorjinx

  • Nov 24th, 2008
 

//Not the best way to do it.. I make ruthless use of memory

//but still gave it a shot ;)

#include <stdio.h>

#include <stdlib.h>

int wap_all(char *ip, char *op, int len, int occupied);

int main(int argc, char **argv)

{

char *ip,*op,*temp;

int i,len;

if(argc !=2)

{

printf("Improper usage. use wap <input string>n");

getch();

exit(1);

}

ip = argv[1];

for(i=0; ip[i]!='';i++);

len=i;

op = (char*)calloc(len,sizeof(char));

temp = (char*)calloc(len,sizeof(char));

for(i=0; i<len;i++)

temp[i]=ip[i];

printf("n");

wap_all(temp,op,len,0);

return 0;

}

int wap_all(char *ip, char *op, int len, int occupied)

{

int i,j,k;

char *temp;

if(len==0)

{

for(i=0;i<occupied;i++)

printf("%c",op[i]);printf(

"n");return 0;

}

temp = (char*)calloc(len-1,sizeof(char));

for(i=0;i<len;i++)

{

for(j=0,k=0;j<len-1;k++)

{

if(k==i)continue;

temp[j]=ip[k];

j++;

}

op[occupied]=ip[i];

wap_all(temp,op,len-1,occupied+1);

}

free(temp);

}

ishan786

  • Feb 15th, 2009
 

#include<stdio.h>

#include<conio.h>

char a[10];

int i,j,k;

void one();

void two();

void three();

void main()

{

       printf("n enter a word ");

       gets(a);

       for(i=0;a[i]!='';i++);

       if(i==1)

       one();

       else if(i==2)

       two();

       else if(i==3)

       three();

       getch();

}


void one()

{

       for(i=0;a[i]!='';i++)

       printf("n%c",a[i]);

}


void two()

{

       one();

       for(i=0;a[i]!='';i++)

       for(j=0;a[j]!='';j++)

       {

             
if(a[i]==a[j])

             
continue;

             
printf("n%c%c",a[i],a[j]);

       }

}


void three()

{

       one();

       two();

       for(i=0;a[i]!='';i++)

       {

             
for(j=0;a[j]!='';j++)

              {


                    
if(i==j)

                    
continue;

                    
for(k=0;a[k]!='';k++)

                    
{

                           
if((i==k)||(j==k))

                           
continue;

                           
printf("n%c%c%c",a[i],a[j],a[k]);

                    
}

              }


       }

}


similarly you can make combination of more letters, this is the simpler way i


think may be there are more so thanks

  Was this answer useful?  Yes

kamal Bhatia

  • Feb 13th, 2015
 

Code
  1. #include<stdio.h>

  2. #include<string.h>

  3. #define a 15

  4. "Enter a word");

  5.         scanf("%s""%d ""%c""

  6. "



  Was this answer useful?  Yes

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