Created
November 25, 2019 02:12
-
-
Save donvito/62d7468591de6fd0061e2171761212d0 to your computer and use it in GitHub Desktop.
Recursion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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