Series: Subject: Topic:
Question: 156 of 828

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
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
Asked by: mailmeskb | Member Since Nov-2008 | Asked on: Nov 13th, 2008

View all questions by mailmeskb

Showing Answers 1 - 2 of 2 Answers

Answered On : Nov 24th, 2008

View all answers by amorjinx

//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 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);}

Yes  1 User has rated as useful.
Login to rate this answer.

Answered On : Feb 15th, 2009

View all answers by ishan786

#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 ithink may be there are more so thanks

Login to rate this answer.

Give your answer:

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

Related Open Questions



twitter fb Linkedin GPlus RSS


Interview Question

 Ask Interview Question?


Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.