1) Write a loop that calculates 12 factorial

num <- 12
ans <- 1
while(num > 1){
 ans <- ans * num
 num <- num -1
}
print(ans)
## [1] 479001600

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

y <- seq(20,50,5) #sequence: start, end, increment by
print(y)
## [1] 20 25 30 35 40 45 50

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.

Formula:

x1 = (- b + sqrt(b^2 - 4ac))/(2a)

x2 = (- b - sqrt(b^2 - 4ac))/(2a)

factorial <- function(a, b, c){
  val <- sqrt(b*b - 4*a*c)
  ans1 <- (-1*b + val)/(2*a)
  ans2 <- (-1*b - val)/(2*a)
  print(paste(ans1, " or ", ans2))
}

factorial(2,5,-3)
## [1] "0.5  or  -3"