golang-exercises/factorial/main.go

30 lines
408 B
Go

package main
import (
"fmt"
"os"
"strconv"
)
var numFinal int = 1
func main() {
if len(os.Args) < 2 || len(os.Args) > 2 {
fmt.Println("Usage: ./factorial 10")
os.Exit(1)
}
arg := os.Args[1]
numFactorial, err := strconv.Atoi(arg)
if err != nil {
fmt.Println(err)
}
for i := 1; i <= numFactorial; i++ {
numFinal = numFinal * i
}
fmt.Println("El número factorizado es:", numFinal)
}