Created
June 24, 2019 15:01
-
-
Save hephyr/ae822323120f0e8eb6785a2008d6c6bd to your computer and use it in GitHub Desktop.
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 factorial_iter(product, counter, max_count int) int { | |
if counter > max_count { | |
return product | |
} else { | |
return factorial_iter(counter*product, counter+1, max_count) | |
} | |
} | |
func factorial2(n int) int { | |
return factorial_iter(1, 1, n) | |
} | |
func factorial(n int) int { | |
if n > 0 { | |
return factorial(n-1) * n | |
} else { | |
return 1 | |
} | |
} | |
func main() { | |
result1 := factorial(6) | |
result2 := factorial2(6) | |
fmt.Println(result1, result2) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment