1. ## 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.

2. 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.

3. how many.

4. Write all the perms for 2, 3 and 4 symbols, and observe the handy pattern they generate.

If you can't manage perms by hand, forget about trying to write the code.

5. N! (Pronounced N factorial)

So if there are 3 items with the set: i.e. 1,2,3
Then there are N! combos.

i.e 3! = 3x2x1 = 6

... 4! = 4x3x2x1= 24 and so on.

6. Do it recursively

Code:
```int factorial(int n)
{
if (n ==0)
return 1;
return n * factorial(n-1)
}```
or something to that effect...

7. thanks a lot to all of you

8. >for example i get 1,2,3 so the combinaions is: 1,3,2 3,1,2 3,2,1
For future reference, combinations and permutations are very different. You want permutations.

>Do it recursively
It's just as easy to do it non-recursively. The factorial example is a good example of a bad way to use recursion.

9. Originally Posted by Prelude
The factorial example is a good example of a bad way to use recursion.
If you were to do it recursively, how would you have done it ?

10. >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:
Code:
```int factorial ( int n )
{
int f = n != 0 ? n : 1;

while ( --n > 1 )
f *= n;

return f;
}```
It's a silly example that displays exactly none of the benefits of recursion and all of the problems.

11. >>A recursive factorial function doesn't buy you anything over a non-recursive function.
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 .

12. She said a recursive factorial function, not a recursive function. Specific vs general.

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:
Code:
```int factorial ( int n )
{
int f = n != 0 ? n : 1;
while ( --n > 1 ) f *= n;
return f;
}```
There, 3 lines, just like the recursive version.

>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?

14. >>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.

15. >I was not talking abt factorial problem but a general case.
Then see Thantos' reply. The off-topic parts of the thread would grow by leaps and bounds if we started talking about recursion in general.