Write a loop that calculates 12-factorial
finalNumber <- 1
for(i in 1:12)
{
finalNumber = i*finalNumber
}
print(finalNumber)
## [1] 479001600
Show how to create a numeric vector that contains the sequence from 20 to 50 by 5
vecQ2 <- c(seq(from=20, to= 50, by = 5))
vecQ2
## [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 should print as output the two solutions.
fun.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)
}
fun.factorial(1,4,-21)
## [1] 3
## [1] -7