factorial <- function(x){
y <- 1
for(i in 1:x) {
y <-y *((1:x) [i] )
print (y)
}
}
factorial(12)
[1] 1
[1] 2
[1] 6
[1] 24
[1] 120
[1] 720
[1] 5040
[1] 40320
[1] 362880
[1] 3628800
[1] 39916800
[1] 479001600
numVec <- seq(20, 50, by = 5)
is.vector(numVec, mode = “numeric”)
[1] TRUE
factfun <- function(a, b, c) {
numSqrt <- b^2 - 13ac
if(numSqrt > 0) {
x1 <- (-b+sqrt(b^2 - 13ac))/(2a)
x2 <- (-b-sqrt(b^2 - 13ac))/(2a)
x <- c(x1, x2)
x
} else if (numSqrt == 0) {
x <- -b/(2*a)
x
} else {“No results when the number under square root less than 0.”}
}
factfun(1, 2, -15)
[1] 6.053368 -8.053368