Write a looop that calculates 12-factorial

factorial <- 1
for (i in 12:1)
{
    factorial <- factorial*i
}
print(factorial)
## [1] 479001600

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

x <- seq(20,50,5)
print(x)
## [1] 20 25 30 35 40 45 50

Create the function “factorial” that takes a,b,c and solve the quadratic equation

factorial <- function(a,b,c)
{
    term <- b^2-4*a*c
    if (term < 0)
    {
      return("The solution is a complex number")
    }
    else
    {
      result <- c((-b + sqrt(term)) / (2*a), (-b - sqrt(term)) / (2*a))
    }
      return(result)
}

Testing a = 2, b = 4, c = -30, the result should be 3 and -5

factorial(2,4,-30)
## [1]  3 -5

Testing a = 1, b = 2, c = 3, the function should declare it being a complex number

factorial(1,2,3)
## [1] "The solution is a complex number"