454,366 Members | 2,106 Online Need help? Post your question and get tips & solutions from a community of 454,366 IT Pros & Developers. It's quick & easy.

# to print permutations...

 P: n/a Suppose we are having 3 variables...a,b,c And we want to print the permutations of these variables...Such as...abc,acb,bca...all 6 of them... But we are not supposed to do it mannually... I want to know that formula by which this can be possible... Then that program will be ok for nnumber of variables.... Can anyone help me for that? May 26 '07 #1
5 Replies

 P: n/a "Shraddha" wrote: Suppose we are having 3 variables...a,b,c And we want to print the permutations of these variables...Such as...abc,acb,bca...all 6 of them... But we are not supposed to do it mannually... I want to know that formula by which this can be possible... Then that program will be ok for nnumber of variables.... Can anyone help me for that? This might help http://en.wikipedia.org/wiki/Permuta...s_in_computing It seems to have some "Pascalish" looking source code. Because of the difficulties of handling templates, I would expect the source code used by next_permutation ( or whatever) is in the \include\ directory of your compiler. I never actually looked, though. May 26 '07 #2

 P: n/a On 5 26 , 9 13 , Shraddha

 P: n/a "osmium" writes: "Shraddha" wrote: >Suppose we are having 3 variables...a,b,cAnd we want to print the permutations of these variables...Suchas...abc,acb,bca...all 6 of them...But we are not supposed to do it mannually...I want to know that formula by which this can be possible...Then that program will be ok for nnumber of variables....Can anyone help me for that? This might help http://en.wikipedia.org/wiki/Permuta...s_in_computing It seems to have some "Pascalish" looking source code. Because of the difficulties of handling templates, I would expect the source code used by next_permutation ( or whatever) is in the \include\ directory of your compiler. I never actually looked, though. The OP is flitting around amongst newsgroups, thus the C++ answer in a C newsgroup. Sorry. The answer is formed with respect to a question and answer the OP got a few days ago. May 26 '07 #4

 P: n/a Shraddha wrote: Suppose we are having 3 variables...a,b,c And we want to print the permutations of these variables...Such as...abc,acb,bca...all 6 of them... But we are not supposed to do it mannually... I want to know that formula by which this can be possible... Then that program will be ok for nnumber of variables.... Can anyone help me for that? Imagine that you had a function that would print all the permutations of an array of N variables. Can you think of a way to use that function to print all the permutations of an array of N+1 variables? Second question: Suppose N is equal to one. Can you think of a way to print all the permutations of a one-element array? If so, then by using the recipe from the first paragraph you can find a method that prints all the permutations of a two-element array. Applying the recipe to that method gives you a way to handle three-element arrays, then four, then five, ... A convenient way to express this in C is to turn the problem around. The recipe tells you how to permute N elements if only you had a method for permuting N-1, which you could do if you had a method for N-2, and so on. Eventually you get down to "If only I had a method for permuting one element," which you'll need to solve on your own. If that's not enough of a hint, you haven't been paying enough attention in class. Ask your teacher for remedial help. -- Eric sosman es*****@acm-dot-org.invalid May 26 '07 #5 