write this program such that the 10th fibonacci term is 89: `def fibo(n) return n if n < 2 && n > 0 a, b = 0, 1 for k in 1..n a, b = b, a + b end a end` in ruby

To modify the given program so that the 10th Fibonacci term is 89, you need to change the loop range from 1..n to 1..(n-2). Additionally, you need to update the initial values of a and b to 1 and 1 respectively.

Here's the modified program:

main.rb
def fibo(n)
  return n if n < 2

  a, b = 1, 1

  for k in 1..(n-2)
    a, b = b, a + b
  end

  a
end
103 chars
12 lines

Now, if you call fibo(10), it will return 89, which is the 10th Fibonacci term.

related categories

gistlibby LogSnag