## Concept:

# Factorial

## Headline

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

- Assign
- Return
*r*.

```
// 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)
```

See also the following collection of implementations:

http://www.willamette.edu/~fruehr/haskell/evolution.html

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

## Metadata

### There are no revisions for this page.

## User contributions

## User edits

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

#### 10 most similar pages:

- Concept:Functional programming - 0.81628555
- Concept:Accumulator parameter - 0.6752504
- Concept:Greatest common divisor - 0.6508413
- Concept:Linear search - 0.63155764
- Concept:Recursion removal - 0.53734106
- Concept:Lazy evaluation - 0.5057472
- Concept:Type class - 0.5045384
- Concept:Control-flow graph - 0.48333675
- Concept:Search algorithm - 0.4604987
- Concept:Insertion sort - 0.44406477

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