Question 1: Write a loop that calculates 12-factorial.

i <- 0
sum <- 1

 for (i in 1:11)
 {
   i <- i+1
   sum <- sum*i 
 }

print(sum)
## [1] 479001600

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

numvec <- c(seq(20, 50, by=5))

numvec
## [1] 20 25 30 35 40 45 50

Question 3: Create the function “factorial” 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 Equation: a\(x^{2}\) + b\(x\) + c = 0

Quadratic Formula: \(x\) = \(\frac{-b\pm\sqrt{b^2 - 4ac}}{2a}\)

factorial <- function(a,b,c)
{
  
two_solutions <- list(c(positive_root=((-b) + sqrt(b^2 - 4*a*c))/ 2*a,negative_root=((-b) - sqrt(b^2 - 4*a*c))/ 2*a))
  
  return(two_solutions)
  
}


## Run Example
 
factorial(1,4,2)
## [[1]]
## positive_root negative_root 
##    -0.5857864    -3.4142136