Question #1 - Loop to calculate 12!

Define function

factorial <- function(input){
  product <- 1
  list <- (1:input)
  for (val in list){
    n <- list[length(list)-val+1]
    product <- product * n
  }
  return(product)
}

Use function to calculate 12!

factorial(12)
## [1] 479001600

Question #2 - Numeric Vector with sequence 20 to 50 by 5

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

Question #3 - Quadratic Function

Define function

quadratic <- function(a,b,c){
  x_1 <- (-b + sqrt(b**2 - 4*a*c)) / (2*a)
  x_2 <- (-b - sqrt(b**2 - 4*a*c)) / (2*a)
  print(x_1)
  print(x_2)
}

Example #1

quadratic(2,-5,-3)
## [1] 3
## [1] -0.5

Example #1

quadratic(2, 9, -5)
## [1] 0.5
## [1] -5