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
- end
- puts "\n enter a number to calculate the Fibonacci sequence"
- value = gets.chomp.to_i
- 10.times do |i|
- puts fib(i)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement