Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Backup Exercise: fibo with function closure

package main

import (
    "fmt"
    "time"
    )

// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
	// initialize some variables that will be updated and saved
	return func() int{
	    // what to do here?
	}
}

func main() {
    start := time.Now()  //just for the benchmarking
    
    n:=int(40)
	f := ?? //initialize function
	for i := 0; i < n-1; i++ {
		fmt.Println(??) //call the closure function
	}
	
	t := time.Now() //just for the benchmarking
    fmt.Println(t.Sub(start))
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.