1. Write a loop that calculates 12-factorial.

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

2. Show how to create a numeric vector that contains the sequence from 20 to 50 by 5.

The solution is:

num_seq <- seq(from = 20, to = 50, by = 5)
num_seq
## [1] 20 25 30 35 40 45 50

3. Create the function “quadratic” that takes a trio of input numbers a, b, and c and solve the quadratic equation. The function should print as output the two solutions.

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.