# Factorial program in erlang using fold, recursion and guards

Erlang, Sachin Puri, 2016-11-19 00:47:12

### Using Recursion

This is an example program to show how can we make use of recursion in erlang to write a factorial program.

```
fact(0)-> 1;
fact(N)-> N * fact(N-1).

```

### Using Recursion (With Guard)

This is an example program to show how can we make use of guard with recursion in erlang to write a factorial program.

```
fact(N) when N == 0 -> 1;
fact(N) when N > 0 -> N * fact(N-1).

```

### Using Fold

This is an example program to show how can we make use of fold in erlang to write a factorial program.

```
lists:foldl(fun(A,B)-> A*B end , 1, [1,2,3,4,5,6,7,8,9,10]).

```

by zzyytt on 05-Dec-2018 01:48 pm

# chrome hearts

•  0 Like
•  0 Dislike
• Report
by zheng on 13-Nov-2018 08:38 am

# valentino

•  0 Like
•  0 Dislike
• Report
by zzyytt on 10-Nov-2018 01:01 pm

# lebron 15

•  0 Like
•  0 Dislike
• Report
by xiaozhengzheng on 04-Nov-2018 11:25 am
2018-11-4 xiaozhengzheng

# oakley sunglasses

•  0 Like
•  0 Dislike
• Report
by wll on 29-Oct-2018 12:14 pm

# goyard

•  0 Like
•  0 Dislike
• Report
by zzyytt on 24-Oct-2018 11:37 am