The solution is:
fact_12 <- 1
for (i in 2:12) {
fact_12 <- fact_12 * i
}
fact_12
## [1] 479001600
To check that the solution is correct:
fact_12 == factorial(12)
## [1] TRUE
The solution is:
num_seq <- seq(from = 20, to = 50, by = 5)
num_seq
## [1] 20 25 30 35 40 45 50
The solution is:
quadratic <- function(a, b, c) {
solution_1 <- (-b + sqrt(b ^ 2 - 4 * a * c)) / (2 * a)
solution_2 <- (-b - sqrt(b ^ 2 - 4 * a * c)) / (2 * a)
return(c(solution_1, solution_2))
}
To test the function, let’s try to find the solutions for the given quadratic equation: 2x² + 5x + 3 = 0 (Correct solutions are: x = -1 and x = -1.5)
quadratic(a = 2, b = 5, c = 3)
## [1] -1.0 -1.5
It seems that the function works as expected.