Fibonacci sequence comparison
Go
package main
import "fmt"
func fib(n int) int {
if n <= 1 {
return n
} else {
return fib(n-1) + fib(n-2)
}
}
func main() {
num := 40
for i := 0; i < num; i++ {
fmt.Println(fib(i))
}
}
Python
def fib(n):
if n <= 1:
return n
else:
return fib(n-1) + fib(n-2)
num = 40
for i in range(num):
print(fib(i))