1.

Write a GO Program to find factorial of a given number.

Answer»

Factorial of a number is the product of multiplication of a number N with every PRECEDING number till it reaches 1. Factorial of 0 is 1.

Example:FACT(1) = 1fact(3) = 3 * 2 * 1 = 6fact(5) = 5 * 4 * 3 * 2 * 1 = 120

CODE:

package mainimport "fmt"//factorial functionfunc factorial(n int) int { if n == 0 { return 1 } return n * factorial(n-1)}FUNC main() { fmt.Println(factorial(7))}

The output of this code would be:

5040


Discussion

No Comment Found