Skip to content

Instantly share code, notes, and snippets.

@MelanieS
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MelanieS/10009381 to your computer and use it in GitHub Desktop.
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.
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