This is the published version of the week 1 solutions.
i <- 12
total <- 12
while (i >= 2)
{
total <- total * (i - 1)
i <- i - 1
}
print (total)
## [1] 479001600
nvect <- c(seq(20, 50, 5))
print (nvect)
## [1] 20 25 30 35 40 45 50
factorial <- function(a, b, c) {
root <- b ^ 2 - 4 * a * c
if (root >= 0){
answer1 = (-b + sqrt(root))/(2 * a)
answer2 = (-b - sqrt(root))/(2 * a)
return(c(answer1, answer2))
}
else {
return(NA)
}
}
print (factorial(1, 5, 1))
## [1] -0.2087122 -4.7912878