Solution Review: Finding Fibonacci Numbers with Array
This lesson discusses the solution to the challenge given in the previous lesson.
package mainimport "fmt"var fib [10]int64 // global array containing Fibonacci valuesfunc fibs() [10]int64{fib[0] = 1 // base cases for 0fib[1] = 1 // base case for 1for i:= 2; i <10; i++ {fib[i] = fib[i-1] + fib[i-2] // recursive case without recursion using array}return fib}func main() {arr := fibs()for i:=0; i < 10; i++ {fmt.Printf("The %d-th Fibonacci number is: %d\n", i, arr[i])}}
Get hands-on with 1400+ tech skills courses.