Q: Exercise: Implement a function FibonacciArray(n) that takesan integer n as input and returns an array of length n whose k-thelement is the k-th Fibonacci number.
This is the code I used but I'm not sure what I'm doingwrong.
func FibonacciArray(n int) []int {
finalSlice := make([]int, n+1)
finalSlice[0] = 1 f
or i := 1; i <= n; i++ {
if i <= 2 { finalSlice[i-1] = 1
} else { var sumSlice int
sumSlice += finalSlice[i-3]
sumSlice += finalSlice[i-2]
finalSlice[i-1] = sumSlice
}
}
return finalSlice
}
Q: Exercise: Implement a function FibonacciArray(n) that takes an integer n as input and returns an array of length n wh
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Q: Exercise: Implement a function FibonacciArray(n) that takes an integer n as input and returns an array of length n wh
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!