当前位置:网站首页>Closure of go (cumulative sum)
Closure of go (cumulative sum)
2022-07-26 10:18:00 【CS beat you】
problem : from 1 To 10 Accumulate and output : It is achieved through free variables .
Such as code :sum It's a free variable
func add() func(int) int{
sum := 0
return func(i int) int{
sum += i
return sum
}
}
func main() {
a := add()
for i:=0;i<10;i++{
fmt.Printf("0+.......+%d: %d\n",i,a(i))
}
}
边栏推荐
猜你喜欢
随机推荐
【C#语言】LINQ概述
【Halcon视觉】形态学腐蚀
数通基础-二层交换原理
简单化构造函数的继承方法(一)- 组合继承
protobuf的基本用法
时间序列异常检测
Employee information management system based on Web
Cause: could't make a guess for solution
Encapsulation of tabbarcontroller
In Net 6.0
Tower of Hanoi II | tower of Hanoi 4 columns
Wechat applet development
句句解析js中的完美 / 缓冲运动框架(新手专用)
Strange Towers of Hanoi|汉诺塔4柱问题
Learning about tensorflow (I)
【Halcon视觉】形态学膨胀
Under win10 64 bit, matlab fails to configure notebook
Flask框架初学-03-模板
详细解析js中的混合方式构造对象(构造加属性,原型加方法)
Learning about opencv (4)
![[Qualcomm][Network] qti服务分析](/img/76/49054ff8c7215eca98cc479ab1d986.png)








