#1: Write a loop that calculates 12-factorial
x <- 1
for(i in 1:12)
{
x <-i*x
}
print(x)
## [1] 479001600
#2: Show how to create a numeric vector that contains the sequence from 20 to 50 by 5
seq(from = 20, to = 50, by = 5)
## [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
#quadratic formula (ax^2)+bx+c = 0
#x1 = (-b + sqrt((b^2)-4ac))/2a
#x2 = (-b - sqrt((b^2)-4ac))/2a
factorial <- function(a, b, c)
{
x1 <- ((-b) + sqrt((b^2)-(4*a*c)))/(2*a)
x2 <- ((-b) - sqrt((b^2)-(4*a*c)))/(2*a)
print(x1)
print(x2)
}
factorial(2, -3, -4)
## [1] 2.350781
## [1] -0.8507811