Solution Review: Compute Factorial of a Number
This lesson discusses the solution to the challenge given in the previous lesson.
Press + to interact
package mainimport ("fmt")func main() {for i := uint64(0); i < uint64(22); i++ {fmt.Printf("Factorial of %d is %d\n", i, Factorial(i)) // calculating factorial of first 21 integers}}// named return variables:func Factorial(n uint64) (fac uint64) {if n<=1{ //base casereturn 1}fac = n * Factorial(n-1) // recursive casereturn}
Get hands-on with 1200+ tech skills courses.