Last active
August 29, 2015 14:14
-
-
Save giwa/03557f5ad6c09ce0ed95 to your computer and use it in GitHub Desktop.
Go by Example: Recursion ref: http://qiita.com/giwa@github/items/aa5e9e89c8a525555f8a
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" | |
// この関数は基礎であるfact(0)にたどり着くまで自分自身を呼び続けます。 | |
func fact(n int) int { | |
if n == 0 { | |
return 1 | |
} | |
return n * fact(n-1) | |
} | |
func main() { | |
fmt.Println(fact(7)) | |
} | |
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
$ go run recursion.go | |
5040 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment