1. Write a loop that calculates 12-factorial
myfactorial <- function(n) {
  result <- 1 # initialize
  for(i in n:1) {
    result <- result * i
  }
  return(result)
}

myfactorial(12)
## [1] 479001600
  1. Show how to create a numeric vector that contains the sequence from 20 to 50 by 5.
myseqvector <- function(start, end, increment) {
  result <- c()
  for(i in seq(from=start, to=end, by=increment)) {
    result <- append(result,i)
  }
  return(result)
}

myseqvector(20, 50, 5)
## [1] 20 25 30 35 40 45 50
  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) {
  root1 <- 1/(2*a)*(-b + sqrt(b^2-4*a*c))
  root2 <- 1/(2*a)*(-b - sqrt(b^2-4*a*c))
  print(root1)
  print(root2)
}

\(\textrm{For example }x^2-x-6=0 \textrm{ is factored into } (x+2)(x-3)=0 \textrm{ in the form }(x-root1)(x-root2)=0\)

quadratic(1,-1,-6)
## [1] 3
## [1] -2