Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def fib(n)
- return n if n < 2
- vals = [0, 1]
- (n-1).times do
- vals.push(vals[-1] + vals[-2])
- end
- return vals
- end
- puts "\n enter a number integer or float to calculate the Fibonacci sequence"
- num = gets.chomp.to_i
- loop do |n|
- puts fib(n)
- break if vals >= num.to_i
- end
- puts "you have reached your destination"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement