https://www.geeksforgeeks.org/program-for-nth-fibonacci-number/ NthFibonacci returns the nth Fibonacci Number
(n uint)
| 8 | |
| 9 | // NthFibonacci returns the nth Fibonacci Number |
| 10 | func NthFibonacci(n uint) uint { |
| 11 | if n == 0 { |
| 12 | return 0 |
| 13 | } |
| 14 | |
| 15 | // n1 and n2 are the (i-1)th and ith Fibonacci numbers, respectively |
| 16 | var n1, n2 uint = 0, 1 |
| 17 | |
| 18 | for i := uint(1); i < n; i++ { |
| 19 | n3 := n1 + n2 |
| 20 | n1 = n2 |
| 21 | n2 = n3 |
| 22 | } |
| 23 | |
| 24 | return n2 |
| 25 | } |
no outgoing calls