Last active
September 8, 2018 14:26
-
-
Save navneetgupta/70cc53e8a77aeb31b36db28904fc81a7 to your computer and use it in GitHub Desktop.
Print n Fibonacci
This file contains hidden or 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
| defmodule FibonacciCalc do | |
| def fibonacci(x) when x <= 0, do: IO.puts "Enter a number greater than 0" | |
| def fibonacci(x) do | |
| calculate_fibonacci(x,1,1) | |
| end | |
| def calculate_fibonacci(x, first, _second ) when x == 1, do: IO.puts "#{first}" | |
| def calculate_fibonacci(x, first, second ) do | |
| IO.puts "#{first}" | |
| calculate_fibonacci(x-1,second, first+second) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment