Skip to content

Instantly share code, notes, and snippets.

@donvito
Created November 25, 2019 02:12
Show Gist options
  • Save donvito/62d7468591de6fd0061e2171761212d0 to your computer and use it in GitHub Desktop.
Save donvito/62d7468591de6fd0061e2171761212d0 to your computer and use it in GitHub Desktop.
Recursion
package main
import (
"fmt"
)
func sum(x int) int {
if x <= 0 {
return 0
} else {
return x + sum(x-1)
}
}
func main() {
y := sum(5)
fmt.Println(y)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment