# Problem 1: Write a loop that calculates 12-factorial
fact = 1
for (i in 1:12)
{
fact = fact * i
}
fact
## [1] 479001600
# Problem 2: Show how to created a numeric vector that contains the sequence
# from 20 to 50 by 5
nums <- c(seq(from = 20, to = 50, by = 5))
nums
## [1] 20 25 30 35 40 45 50
# Problem 3: Create the function "quadratic" that takes a trio of input
# numbers a, b, and c and solves the quadratic equation. The function should
# print as output the two solutions.
# Please note: I wanted to add checks to ensure that a, b, and c are numeric
# and that a is not zero, but wasn't sure how to do that.
quadratic <- function(a, b, c)
{
disc <- sqrt(b^2 - (4*a*c))
quadpos <- (b*-1 + disc)/(2*a)
quadneg <- (b*-1 - disc)/(2*a)
print("The two solutions are: ")
print(quadpos)
print(quadneg)
}
quadratic(1,4,-5)
## [1] "The two solutions are: "
## [1] 1
## [1] -5