Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

fibonacci sums ruby

# Write a method that finds the sum of the first n fibonacci numbers recursively. 
# Assume n > 0.

def fibs_sum(n)
  return 1 if n == 1
  return 2 if n == 2
  n + fibs_sum(n-1)
end
 
PREVIOUS NEXT
Tagged: #fibonacci #sums #ruby
ADD COMMENT
Topic
Name
7+2 =