DIGIT-ARC read-only archive · snapshot: July 23, 2026

C code to display all combinations of a word

5 posts · originally from https://geek.digit.in/community/threads/c-code-to-display-all-combinations-of-a-word.151792/

A
ajay600 Original post #1
Jan 25, 2012 at 7:20 PM
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
Neuron #2
Jan 25, 2012 at 8:25 PM
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
d6bmg #3
Jan 25, 2012 at 10:16 PM
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 at 5:15 PM
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 at 5:38 PM
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.