GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 438 of 453    Print  
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



  
Total Answers and Comments: 2 Last Update: February 15, 2009     Asked by: mailmeskb 
  
 Sponsored Links

 
 Best Rated Answer
Submitted 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 <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);

}



Above answer was rated as good by the following members:
chandrakumar.g
November 24, 2008 23:04:36   #1  
amorjinx Member Since: November 2008   Contribution: 1    

RE: display different combinations of some letters forming a word

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

}


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
February 15, 2009 00:58:50   #2  
ishan786 Member Since: February 2009   Contribution: 1    

RE: display different combinations of some letters forming a word

#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


 
Is this answer useful? Yes | No

 Related Questions

Streams can be classified into two types: text streams and binary streams. Text streams are interpreted, with a maximum length of 255 characters. With text streams, carriage return/line feed combinations 
Latest Answer : Will you please explain how binary mode takes less memory? ...

Pointers to functions are interesting when you pass them to other functions. A function that takes function pointers says, in effect, “Part of what I do can be customized. Give me a pointer to a 
Tags : Pointer

Latest Answer : excellent answer ...
Read Answers (4) | Asked by : suresh

Make a program that will read a string and after that it determine the total of the letters, total of spaces,total digits,and total characters. example: i enter a string, hi 123 and the output is like this:TOTAL LETTERS:2TOTAL SPACES:2TOTAL DIGITS:3TOTAL CHARACTERS:7 pls. help me i need the answer a.s.a.p. thank you.
Read Answers (2) | Asked by : gilbert

Write a program that will print out all the possible combinations of the charecters present in the given string.for example:monu,numo,nmou etc.
Read Answers (3) | Asked by : chanchal

Write sample code or algorithim to get all possible combinations of data that will be entered from keyboard
like, If i enter 1 2 3 then it should show 1 2 31 3 2 2 1 3 All 6 possible combnations 

suppose i have given like integer 123.....then print like all the combinations 111,112,113,121......up to 333.. 
Latest Answer : /*to print possible patern using given no*/#include#includevoid main(){ int a[100],b[100],n,x=1,y,k,j,i,m,c; clrscr(); printf("enter no of nost"); scanf("%d",&n); m=n-1; printf("nenter ...

Write a program to generate all combinations of 1,2 and 3 using for loop? 
Latest Answer : int main (){  int i,j,k;  for(i=1;i

Write a program in C which will print all the possible combination of a given word. E.G. if the word is ABCD then the output should be ABCD, ABDC, ACBD, ACDB, ADBC, ADCB, BACD, BADC, BCAD, BCDA, BDAC, 
Latest Answer : #include #include #include typedef unsigned int u32;#define SWAP(a, b) do { a ^= b; b ^= a; a ^= b; } while (0)u32 print_ctr;void PrintAllPerms(char *str);void RecurseAllPerms(char *str, u32 len, char *base);int ...

Write a program to find distinct word from file,and to check a particular word present or not in each line  
Latest Answer : Here is how I would write this in C++.....Enjoy// // File:   FindWordCPP.cc// Author: Steven Ong//// Created on February 19, 2008, 11:05 PM//#include #include #include #include #include ...


 Sponsored Links

 
Related Articles

Concepts of Object-Oriented Programming

Object Oriented JavaScript In this chapter you ll learn about OOP Object Oriented Programming and how it relates to JavaScript As an ASP NET developer you probably have some experience working with objects and you may even be familiar with concepts such as inheritance However unless you re already a
 

SQL Programming

SQL Programming Overview Anybody who has done something for a long time has probably wanted to change how things work at some point or another. A worker at a mill might have found a more efficient way of cutting logs, or a mathematics teacher might have had a hand in changing a school&rsquo;s al
 

The Interview Snafu

How to turn someone else&rsquo;s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won&rsquo;t get over the line without a polished, prof
 

The Importance of Cover Letters in Career Assessment

Along with the resume, job seekers should always include a cover letter when applying for a job. The cover letter, which is read first, is your chance to stand out from the crowd when entering a hiring stack of resumes. It can make the difference between getting the interview and having your resume
 

WinRunner Programming Concepts

If you want to create WinRunner scripts that are highly efficient, there are important programming concepts that you will want to become familiar with. Understanding these concepts will provide you with a large number of key benefits. In addition to understanding these concepts, you must also learn
 

Programming Languages Certification

IT Certification programs have several options that will offer you the best knowledge.&nbsp; By learning everything that you need to know about information technology you will be able to open new doors to your career and personal business desires.&nbsp; IT Certification offers several vari
 

Neuro-linguistic Programming Methods

Neuro linguistic Programming Methods There are several methods used for performing Neuro linguistic Programming on an individual for obtaining insights into the psyche of the person in order to correct to modify certain patterns of behavior These techniques are also used for Neuro linguistic trainin
 

Importance of Proper English during Job Interview

Importance of Proper English during Job Interview Your job interview is crucially important and it will determine whether or not you will get the job Depending on the type of job you re going for it is very important for you to use proper English In most cases jobs which offer higher salaries will h
 

The Difficult Past of Neuro-linguistic programming

The Difficult Past of Neuro linguistic programming Neuro linguistic programming has had a rocky past with a number of lawsuits rivalry unsystematic development and intermittent progress During the 1980s the two founders separated after the lawsuit filed by Bandler Bandler went on to file several law
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape