1. Write a loop that calculates 12-factorial
fact <- 1
for (i in c(1:12)) {
  fact <- fact * i
}
print(factorial(12) == fact)
## [1] TRUE
sprintf('12 factorial = %i', fact)
## [1] "12 factorial = 479001600"
  1. Show how to create a numeric vector that contains the sequence from 20 to 50 by 5.
vect1 <- c(20:50)
vect1 <- as.numeric(vect1)
vect1 <- vect1[vect1 %% 5 == 0]
print(vect1)
## [1] 20 25 30 35 40 45 50
vect2 <- c(20:50)[c(20:50) %% 5 == 0]

# Check
print(all(vect1 == vect2) == 1)
## [1] TRUE
  1. 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.
quadratic <- function(a, b, c) {
  numeratorp <- -b + sqrt(b^2 - 4 * a * c)
  numeratorn <- -b - sqrt(b^2 - 4 * a * c)
  denominator <- 2 * a
  ans <- c(numeratorp /denominator, numeratorn / denominator)
  
  return (ans)
}

print('Quadratic roots of X^2 + 5X + 6 is')
## [1] "Quadratic roots of X^2 + 5X + 6 is"
print(quadratic(1, 5, 6))
## [1] -2 -3