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.last
- if vals.last >= num then
- end
- end
- puts "\n enter a number (integer or float) to calculate the Fibonacci sequence"
- num = gets.chomp.to_i
- 50.times do |n|
- puts fib(n)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement