Numbers combinations(possibilities)

This is a discussion on Numbers combinations(possibilities) within the C Programming forums, part of the General Programming Boards category; how can i find how many combinations(possibilities) can i do from the numbers that i get.
for example i get ...

Numbers combinations(possibilities)

how can i find how many combinations(possibilities) can i do from the numbers that i get.
for example i get 1,2,3 so the combinaions is: 1,3,2 3,1,2 3,2,1
......(there is more)
you have to use all the three numbers in the combination.

Hang on. Are you trying to find out how many permutations there are, or what they are ?

Ray

Originally Posted by snaidis

how can i find how many combinations(possibilities) can i do from the numbers that i get.
for example i get 1,2,3 so the combinaions is: 1,3,2 3,1,2 3,2,1
......(there is more)
you have to use all the three numbers in the combination.

>If you were to do it recursively, how would you have done it ?
I wouldn't have done it recursively, that's the point. A recursive factorial function doesn't buy you anything over a non-recursive function:

>>A recursive factorial function doesn't buy you anything over a non-recursive function.
Sometimes it buy.
1.It makes the code short n sweet.
2.Sometimes its easy to find recursive than iterative soln for a novice like me.
Of course recursive soln have lots of overhead but who cares when it is short program .

Long time no C. I need to learn the language again.
Help a man when he is in trouble and he will remember you when he is in trouble again.
You learn in life when you lose.
Complex problems have simple, easy to understand wrong answers.
"A ship in the harbour is safe, but that's not what ships are built
for"

>Sometimes it buy.
If your compiler fixes tail recursion then you won't see any difference, but unless there's a serious benefit to recursion (which there isn't in this case), you would be better off writing something that is more likely to be good everywhere.

>1.It makes the code short n sweet.
So 3 lines is short and sweet, and 4 lines is ridiculously long? I can take out whitespace and merge the loop condition and body if it makes you feel better:

>2.Sometimes its easy to find recursive than iterative soln for a novice like me.
Well, aside from being trivial for even the greenest C programmer, I just posted an interative solution.

>Of course recursive soln have lots of overhead but who cares when it is short program
Factorials are useful. You'll find that as a utility, a function that gives you the factorial of N will be used in programs of any size. So it's wise to come up with the best solution you can manage, and because a recursive solution has no benefit over a non-recursive solution, why are you even bothering to defend your position?

>>So 3 lines is short and sweet, and 4 lines is ridiculously long?
>>Well, aside from being trivial for even the greenest C programmer, I just posted an interative solution.
I was not talking abt factorial problem but a general case.
>>why are you even bothering to defend your position?
I was not defending or arguing.I was telling my opinion or with which i am comfortable with.

Long time no C. I need to learn the language again.
Help a man when he is in trouble and he will remember you when he is in trouble again.
You learn in life when you lose.
Complex problems have simple, easy to understand wrong answers.
"A ship in the harbour is safe, but that's not what ships are built
for"