Last active
August 29, 2015 13:58
-
-
Save MelanieS/10009381 to your computer and use it in GitHub Desktop.
Calculates user defined nth number in the Fibonacci sequence. Script doesn't utilize recursion.
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
puts "How many Fibonacci numbers would you like?" | |
n = gets.to_i | |
puts "Awesome! I'll get started on that right away!" | |
def fibonacci(n) | |
array = [] | |
a,b = 0,1 | |
n.times do | |
array << a | |
a,b = b,a+b | |
end | |
puts "Here are your requested Fibonacci numbers:" | |
puts array.to_s | |
end | |
fibonacci(n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment