12345*6=620
i right a program and its output 620 means the facturial of 6 using recursion. i could not uderstand factorial using recursion. please help me .

The factorial of a positive integer n, n!, is `1 * 2 * 3 * ... * n` for n > 0 and 1 for n = 0. Would take you about 1 second to find on google.

The simple case is when n = 0, you simply return …

## All 2 Replies

The factorial of a positive integer n, n!, is `1 * 2 * 3 * ... * n` for n > 0 and 1 for n = 0. Would take you about 1 second to find on google.

The simple case is when n = 0, you simply return 1.

``````if (n == 0)
return 1;
``````

Then for other cases we want to express the problem of calculating the factorial using a smaller version of the same problem so we can solve it recursively. It's easy to see that `fac(n) = n * fac(n - 1)`.

``````else
return n * fac(n - 1);
``````

Btw. facorial of 6 = 720. 6! = 720 check it out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.