Go Program to find factorial of a number


In this program, You will learn how to find factorial of a number in Go.


3! = 1 * 2 * 3 => 6

4! = 1 * 2 * 3 * 4 => 24

find factorial number

Example: How to find factorial of a number in Go

package main

import "fmt"

func main() {

	var n int
	fmt.Print("Enter a number:")
	fmt.Scan(&n)

	f := 1
	for i := 1; i <= n; i++ {
		f = f * i
	}

	fmt.Println("Factorial is:", f)
}

Output:

Enter a number:4
Factorial is: 24