21 lines
375 B
Go
21 lines
375 B
Go
package functions
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
func MyFibonacci(count int) (fibonaccivalue int, error error) {
|
|
fibonaccivalue = 1
|
|
error = nil
|
|
var prev_fibonacci int = 0
|
|
|
|
if count < 1 {
|
|
return -1, fmt.Errorf("%d is not a positive integer", count)
|
|
}
|
|
for i := 1; i < count; i++ {
|
|
fibonaccivalue += prev_fibonacci
|
|
prev_fibonacci = fibonaccivalue - prev_fibonacci
|
|
}
|
|
return
|
|
}
|