#Write a loop that calculates 12-factorial get_factorial <- function(n = 0) {
#Checking if n is negative if (n < 0) return(-1)
#If n is zero we return 1 if (n == 0) return(1)
#Loop the factorial my_factorial <- 1 for (i in 1:n) { my_factorial <- my_factorial * i } return(my_factorial) }
get_factorial(12)
#Show how to create a numeric vector that contains the sequence from 20 to 50 by 5. five_vector <- c(seq.int(20, 50, by = 5)) five_vector
#Create the function “quad” 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. quad <- function(a, b, c) { discriminant <- b^2 - 4ac if (discriminant < 0) { return(“No real solutions”) } else { sol1 <- (-b + sqrt(discriminant)) / (2a) sol2 <- (-b - sqrt(discriminant)) / (2a) return(c(sol1, sol2)) } }
#Test the function quad(1, 2, 1) quad(1, 6, 5) quad(1, 1, 1)