# C code to display all combinations of a word



## ajay600 (Jan 25, 2012)

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 (Jan 25, 2012)

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 (Jan 25, 2012)

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 (Jan 26, 2012)

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 (Jan 26, 2012)

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.


----------

