2025-07-13 22:13:35 +02:00
|
|
|
package functions
|
|
|
|
|
|
2025-07-24 11:37:38 +02:00
|
|
|
import(
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func MyFibonacci(count int) (fibonaccivalue int, error error) {
|
2025-07-13 22:13:35 +02:00
|
|
|
fibonaccivalue = 1
|
2025-07-24 11:37:38 +02:00
|
|
|
error = nil
|
2025-07-13 22:13:35 +02:00
|
|
|
var prev_fibonacci int = 0
|
|
|
|
|
|
2025-07-24 11:37:38 +02:00
|
|
|
if count < 1 {
|
|
|
|
|
return -1, errors.New(fmt.Sprintf("%d is not a positive integer.",count))
|
|
|
|
|
}
|
2025-07-13 22:13:35 +02:00
|
|
|
for i := 1; i < count; i++ {
|
|
|
|
|
fibonaccivalue += prev_fibonacci
|
|
|
|
|
prev_fibonacci = fibonaccivalue - prev_fibonacci
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|