1. Write a loop that calculates 12-factorial

factorial <- 1
for (s in 1:12) {
  factorial <- factorial * s
}

print(paste("The factorial of 12 is:", factorial))
## [1] "The factorial of 12 is: 479001600"

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

n <- seq(20,50,5)
as.numeric(n)
## [1] 20 25 30 35 40 45 50

3. Create the function “quad” 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. Please run and test your answer for (1,2,1), (1,6,5) and (1,1,1).

quad <- function(a,b,c)
{
  if (b**2 - (4*a*c) >= 0)
  {
  firstNum <- (-b + (b**2 - (4*a*c))^0.5) / (2*a)
  secondNum <- (-b - (b**2 - (4*a*c))^0.5) / (2*a)
  cat(firstNum, secondNum)
  }  
  else
  {
  myString <- "No Output Available!"
  print ( myString)
  }
}

quad(1,2,1)
## -1 -1
quad(1,6,5)
## -1 -5
quad(1,1,1)
## [1] "No Output Available!"