2025-07-13 22:13:35 +02:00
|
|
|
package functions
|
|
|
|
|
|
2025-08-25 13:16:43 +02:00
|
|
|
import (
|
2025-07-24 11:37:38 +02:00
|
|
|
"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 {
|
2025-08-25 13:16:43 +02:00
|
|
|
return -1, fmt.Errorf("%d is not a positive integer", count)
|
2025-07-24 11:37:38 +02:00
|
|
|
}
|
2025-07-13 22:13:35 +02:00
|
|
|
for i := 1; i < count; i++ {
|
|
|
|
|
fibonaccivalue += prev_fibonacci
|
|
|
|
|
prev_fibonacci = fibonaccivalue - prev_fibonacci
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|