inst/testdata/prov_factorial_2021-03-31T12.01.36EDT/scripts/factorial.R

factorial <- function (num) {
  if (num < 0) {
    return (-1)
  }
  answer = 1
  
  for (i in 0: num) {
    answer = answer * i
  }
  
  return (answer)
}

cat ("The factorial of", 5, "is", factorial (5), "\n")
cat ("The factorial of", -5, "is", factorial (-5), "\n")
cat ("The factorial of", 0, "is", factorial (0), "\n")

Try the provExplainR package in your browser

Any scripts or data that you put into this service are public.

provExplainR documentation built on Aug. 16, 2022, 1:07 a.m.