Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 25-01-2012, 07:20 PM   #1 (permalink)
Right Off the Assembly Line
 
Join Date: Nov 2011
Posts: 29
Default C code to display all combinations of a word


i attended an intervew and i got a C program question where i need to input a word and print all combinations of the word

say input= abc
output=
bac
acb
cab
cba...

All i could manage was to revere the word .. abc to cba and i was eliminated in the interview

Now i need to learn the logic for this .. kindly provide a C code to achive this output
ajay600 is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 25-01-2012, 08:25 PM   #2 (permalink)
Electronic.
 
Neuron's Avatar
 
Join Date: Jun 2010
Location: Elsweyr
Posts: 530
Default Re: C code to display all combinations of a word

I'll help you a bit more on the logic.Try to write the prog on your own.If you still can't i'll post the program.

First print all the possible words with a as the first letter.Then print all the words with b as the first letter and finally that of c.So the output should be like this.

abc
acb
bac
bca
cab
cba

This is simple, you should be able to do it on your own.
__________________
I don't always make sense,but when I do,I don't.
Neuron is offline  
Old 25-01-2012, 10:16 PM   #3 (permalink)
BMG ftw!!
 
d6bmg's Avatar
 
Join Date: Aug 2011
Location: Kolkata
Posts: 3,815
Default Re: C code to display all combinations of a word

1. scan ASCII values.
2. group identical letter(s) if there are any.
3. then create 2d array/pointer using those letters & exclude similar rows.
4. display them.
d6bmg is offline  
Old 26-01-2012, 05:15 PM   #4 (permalink)
I'm a Wannabe Hacker
 
Prime_Coder's Avatar
 
Join Date: Apr 2011
Location: Oxford of D East!
Posts: 235
Default Re: C code to display all combinations of a word

Welcome to TDF.

Use search engines before asking for questions. If you didn't get answers, then ask the question here.

A simple searching for your query resulted into this link: Write a C program to print all permutations of a given string
__________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
Prime_Coder is offline  
Old 26-01-2012, 05:38 PM   #5 (permalink)
In The Zone
 
cute.bandar's Avatar
 
Join Date: Jan 2010
Posts: 408
Default Re: C code to display all combinations of a word

Here's how it has been done in php : http://stackoverflow.com/questions/6...rds-characters. This guy used recursion.
__________________
Computer parts search Engine(for india) : http://goo.gl/Sg8Yv
cute.bandar is online now  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Charan
- by Sarath
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 12:39 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2