Last active
June 13, 2019 19:42
-
-
Save mahmoud-eskandari/f05e013dc0c65bd50ef6109abd25d641 to your computer and use it in GitHub Desktop.
Recursive factorial calculator without if
This file contains hidden or 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 main() { | |
fmt.Println(Factorial(65)) | |
} | |
func Factorial(n uint64) uint64 { | |
factorialOp(&n, 1, n) | |
return n | |
} | |
func factorialOp(n *uint64, current uint64, On uint64) bool { | |
*n *= current | |
current++ | |
return current >= On || factorialOp(n, current, On) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment