Skip to content

Instantly share code, notes, and snippets.

@kahunacohen
Created June 8, 2023 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kahunacohen/a0653916c7a11a78e7b2fff41674f916 to your computer and use it in GitHub Desktop.
Save kahunacohen/a0653916c7a11a78e7b2fff41674f916 to your computer and use it in GitHub Desktop.
package main
import "fmt"
func fac(n int) int {
ret := 1
for i := n; i > 1; i-- {
ret *= i
}
return ret
}
func facR(n int) int {
if n == 1 {
return 1
}
return n * facR(n-1)
}
func main() {
fmt.Println(fac(5))
fmt.Println(facR(5))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment