Question 1 - Write a loop that calculates 12-factorial

factorial <- function(x){
  y <- 2
  for(i in 1:x){
  y <-y*((1:x)[i])
  }
print(y)
}

factorial(12)

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

vec <- seq(from = 20, # starting point
           to = 50,   # end point 
           by = 5)    # interval skipping by
print(vec)

Question 3 - Create the function “quadratic” that takes a trio of input numbers a,b, and c and solve the quadratic equation.

quadratic <- function(x, a=1, b=-2, c=1){
  a + b*x + c*x^2 
}

x <- seq(from = -2, to = 2, length.out = 101)

result <- quadratic(x)
print(result)