Debug program

Report a typo

Your friend Paul also tries to study Golang. He writes a new program, which calculates the factorial of a number. But when he checks the result — it's wrong! Help Paul write the correct code.

Sample Input 1:

Sample Output 1:

Factorial of a number 6 is 720
Factorial of a number 8 is 40320
Factorial of a number 11 is 39916800
Write a program in Go
package main

import (
"os"
)

func main() {
logger := log.New(os.Stdout, "", log.Lmsgprefix)
var array = []int64{6, 8, 11}
for i, num := range array {
logger.Println("Factorial of a number %d is %d\n", i, factorial(num))
}
}

func factorial(num int64) int64 {
res := int64(0)
for i := int64(0); i < num; i++ {
res *= i
}
return res
}
___

Create a free account to access the full topic