Sum of the first n Fibonacci numbers in Haskell
I have to calculate the sum of the first n Fibonacci numbers. The function fib returns the nth Fibonnaci number, but I don't know how to sum only the first n numbers (where n is given). fib :: Int -> Int fib 0 = 0 fib 1 = 1 fib x = fib (x-1) + fib (x-2) sumFib :: Int -> Int sumFib x = if x == fib x then x+fib x else fib x
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.