# How to print permutations?

Discussion in 'C++' started by Shraddha, May 25, 2007.

If we have three variables a,b,c...which are char variables....then
hoe to print there all permutations?
for example....abc, bac, cab.......all of them....

2. ### Deniz DoganGuest

> If we have three variables a,b,c...which are char variables....then
> hoe to print there all permutations?
> for example....abc, bac, cab.......all of them....
>

Are all of these questions school work or something?

Deniz Dogan, May 25, 2007

3. ### =?iso-8859-1?q?Erik_Wikstr=F6m?=Guest

On 25 Maj, 14:44, Shraddha <> wrote:
> If we have three variables a,b,c...which are char variables....then
> hoe to print there all permutations?
> for example....abc, bac, cab.......all of them....

Perhaps std::next_permutation() can be of use.

--
Erik WikstrĂ¶m

=?iso-8859-1?q?Erik_Wikstr=F6m?=, May 25, 2007
4. ### osmiumGuest

> If we have three variables a,b,c...which are char variables....then
> hoe to print there all permutations?
> for example....abc, bac, cab.......all of them....

Use std::next_permutation() in <algorithm>.

osmium, May 25, 2007

On May 25, 5:50 pm, Deniz Dogan <> wrote:
> > If we have three variables a,b,c...which are char variables....then
> > hoe to print there all permutations?
> > for example....abc, bac, cab.......all of them....

>
> Are all of these questions school work or something?

Hi Deniz...
This is not a school work...
Actually these permutations are not supposed to be printed mannually.
There is a formula for that permutations....b'coz of which we can do
that program within 5-7 lines...that works not only for 3 variables
but for n number of characters.
But I am not aware of that formula...so I just want to know that
formula....

6. ### John HarrisonGuest

> On May 25, 5:50 pm, Deniz Dogan <> wrote:
>>> If we have three variables a,b,c...which are char variables....then
>>> hoe to print there all permutations?
>>> for example....abc, bac, cab.......all of them....

>> Are all of these questions school work or something?

>
> Hi Deniz...
> This is not a school work...
> Actually these permutations are not supposed to be printed mannually.
> There is a formula for that permutations....b'coz of which we can do
> that program within 5-7 lines...that works not only for 3 variables
> but for n number of characters.
> But I am not aware of that formula...so I just want to know that
> formula....
>

http://www.von-oppen.com/doc/cuj/html/20.03/nelson/nelson.htm

It has the 'formula' you want (actually the algorithm) if you are
prepared to do a little work and actually understand.

john

John Harrison, May 26, 2007