Sum of first n fibonacci numbers haskell
I have tu calculate the sum of first n fibonacci numbers. fib function returns the nth fibonnaci number. But i dont know how to sum only the first n numbers ( n given number ) 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.