I need to know how to find the factorial (5!=125) of a variable and, using it and for loops, put all of the possible combinations in an array.

Printable View

- 05-20-2005AdamLANNew program need help with factorials
I need to know how to find the factorial (5!=125) of a variable and, using it and for loops, put all of the possible combinations in an array.

- 05-20-2005hk_mp5kpdwQuote:

Originally Posted by**AdamLAN**

Quote:

Originally Posted by**AdamLAN**

- 05-20-2005xErath
factorial of x is x*factorial(x-1), and factorial 0 is 1

have fun... I'd sugest a cicle instead of recursion... recursion does functions call, which have a big overhead and use lots of stack. - 05-20-2005TograQuote:

Originally Posted by**AdamLAN**

- 05-20-2005DougDbug
AdamLAN,

Do you know what a factorial is? Can you do it by hand or on a calculator? ... I mean a calculator without a factorial button.

5! means 1 x 2 x 3 x 4 x 5 = 120. (Of course, that's NOT C++ because x does NOT mean multiply in C++.) :)

**Step 1**

If you can't figure-out the whole program, how about starting with a**loop**that generates the sequential integers 1 thru n: 1, 2, 3, 4...

**Step 2**

When that's working, add the code to calculate the**factorials**.

**Step 3**

When you get that working, add the**array**stuff.

I assume that by "all the possible combinations" you mean this all of the factorials up to n: 1, 2, 6, 24...