# Factorial

The product 1 * ... * n for a given natural number n

## Illustration

We face an algorithmic problem because the factorial can be computed by a (simple) algorithm. Assume that n is a natural number. Then, the following steps compute the factorial of n:

• Initialize a variable r with 1.
• Repeat the following step until n equals 0:
• Assign n*r to r.
• Decrement n.
• Return r.
Here is also an implementation in Language:Java:

```  // An imperative definition of the factorial function
public static int factorial(int n) {
int result = 1;
for (int i=n; i>1; i--)
result = result * i;
return result;
}
```

Here is also an implementation in Language:Haskell:

```-- A recursive definition of the factorial function
factorial n =
if n==0
then 1
else n * factorial (n-1)
```

## Citation

(http://en.wikipedia.org/wiki/Factorial, 21 April 2013)

In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example,

5! = 5 * 4 * 3 * 2 * 1 = 120

The value of 0! is 1, according to the convention for an empty product.

## User contributions

This user never has never made submissions.

## Syntax for editing wiki

For you are available next options:

will make text bold.

will make text italic.

will make text underlined.

will make text striked.

will allow you to paste code headline into the page.

will allow you to link into the page.

will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

will allow you to paste image into the page.

is list with bullets.

is list with numbers.

will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

will allow your to insert code snippets from @worker.

## Syntax for editing wiki

For you are available next options:

will make text bold.

will make text italic.

will make text underlined.

will make text striked.

will allow you to paste code headline into the page.

will allow you to link into the page.

will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

will allow you to paste image into the page.

is list with bullets.

is list with numbers.

will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

will allow your to insert code snippets from @worker.