Created
December 18, 2019 10:52
-
-
Save podanypepa/56d08d289c691edaa449f8a7918981da to your computer and use it in GitHub Desktop.
fak func
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" | |
"os" | |
"strconv" | |
) | |
func fak(n int) int { | |
if n == 1 { | |
return n | |
} | |
return n + fak(n-1) | |
} | |
func main() { | |
if len(os.Args) < 2 { | |
os.Exit(1) | |
} | |
n, _ := strconv.Atoi(os.Args[1]) | |
fmt.Printf("%d: %d\n", n, fak(n)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment