## 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.82159084
- Concept:Accumulator parameter - 0.6747304
- Concept:Greatest common divisor - 0.6609727
- Concept:Linear search - 0.63661724
- Concept:Recursion removal - 0.5397466
- Concept:Type class - 0.5160826
- Concept:Lazy evaluation - 0.5050172
- Concept:Control-flow graph - 0.48270315
- Concept:Search algorithm - 0.46203712
- Concept:Insertion sort - 0.44340092

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