Write a loop that calculates 12-factorial

#quickly check to obtain the answer for 12-factorial by using the factorial function
factorial(12)
## [1] 479001600
#create an f variable which will hold the value of 1
#create the for loop with a sequence of 1 through 12 since the factorial of 12 is obtained by multiplying every number up until 12
#since the f variable carries a value of 1 the loop tells R to multiply 1 against the sequence and apply each answer to the index variable
f <- 1
for(i in 1:12){
    f <- f*((1:12)[i])
    print(f)}
## [1] 1
## [1] 2
## [1] 6
## [1] 24
## [1] 120
## [1] 720
## [1] 5040
## [1] 40320
## [1] 362880
## [1] 3628800
## [1] 39916800
## [1] 479001600

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

#variable entitled numvec will host the sequence
numvec <- seq(from=20, to=50,by = 5)
#display the sequence
numvec
## [1] 20 25 30 35 40 45 50

Create the function “factorial” that takes a trio of input numbers a, b, and c and solve the quadratic equation. The function shoud print as output the two solutions.

#the quadratic equation is ax^2 + bx + c = 0, must always equal to 0
#the disciminant of a quadratic is equal to b^2 - 4ac
factorial <- function(a,b,c){
    dis <-b^2 - (4 * a * c)
    if (dis > 0){
#according to virtualnerd.com when the numbers are plugged in -b will have two options
#-b will have to add and subtract the square root of b^2-4ac
        xadd <-((-b + sqrt(dis))/(2 * a))
        xsub <-((-b - sqrt(dis))/(2 * a))
        print(xadd)
        print(xsub)
        listx <- list(xadd,xsub)
        return (listx)
}
        else if (dis==0){
            xadd <- -b / (2 * a)
            return(xadd)
}       else {
                break
}
}
factorial(2,5,3)
## [1] -1
## [1] -1.5
## [[1]]
## [1] -1
## 
## [[2]]
## [1] -1.5
#used variables from virtualnerd.com to