C code to display all combinations of a word

Status
Not open for further replies.

ajay600

Broken In
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
 

Neuron

Electronic.
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.
 

d6bmg

BMG ftw!!
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.
 

Prime_Coder

I'm a Wannabe Hacker
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
 

cute.bandar

Cyborg Agent
Here's how it has been done in php : *stackoverflow.com/questions/6797578/how-can-i-get-all-unique-combinations-of-a-words-characters. This guy used recursion.
 
Status
Not open for further replies.
Top Bottom