Created
February 24, 2017 19:38
-
-
Save muhammednagy/ea75ed93795b5112b82ab5439ccbbe69 to your computer and use it in GitHub Desktop.
Recursion in erlang (Fibonacci, factorial, n dimensions)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(recursion). | |
-export([fac/1,fib/1,cut/1]). | |
fac(0) -> | |
1; | |
fac(N) when N>0 -> | |
fac(N-1) * N; | |
fac(N) when N<0 -> | |
io:fwrite("Postieve number please", []). | |
fib(0) -> 0; | |
fib(1) -> 1; | |
fib(N) when N>0 -> | |
fib(N-1)+fib(N-2). | |
cut(0) -> 1; | |
cut(1) -> 2; | |
cut(N) when N>0 -> | |
cut(N-1)+N. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment