# Factorial in Roco

Example for versions
Roco 20071014

This example uses iterative definition of factorial. Cell [0] stores the current number, cell [1] is temporary, and cell [2] stores factorial of current number.

```
co calc{
/* break the loop when the counter is 17 - the number for which we don't need factorial */
eq [1] [0] 17
if [1] ac
/* output current factorial */
iout [0]
cout 33
cout 32
cout 61
cout 32
iout [2]
cout 13
cout 10
/* calculate next number and store it to [2]*/
add [0] [0] 1
mul [2] [2] [0]
}
/* initialize with 0! = 1 */
set [0] 0
set [2] 1
ca calc
ac
```

## Comments

]]>blog comments powered by Disqus

]]>