give me fibonacci code in golang
- User
give me fibonacci code in golang
- Assistant
Sure, the Fibonacci sequence is a series of numbers where the next number is found by adding the two numbers before it. Here's an example of how to generate the Fibonacci sequence in Go (Golang):
gopackage main import "fmt" func fibonacci(n int) []int { fibSequence := make([]int, n) for i := 0; i < n; i++ { if i <= 1 { fibSequence[i] = i } else { fibSequence[i] = fibSequence[i-1] + fibSequence[i-2] } } return fibSequence } func main() { n := 10 // You can change this to generate more or fewer Fibonacci numbers sequence := fibonacci(n) fmt.Println(sequence) }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.