Write a loop that calculates 12-factorial:
j <- 1
for (i in 1:12) {
j <- j*i
}
print(j)
## [1] 479001600
Create a numeric vector that contains the sequence from 20 to 50 by 5:
q2v <- c(4:10)*5
print(q2v)
## [1] 20 25 30 35 40 45 50
Create the function “quad” :
quad <- function(a,b,c){
discriminant <- b^2 - 4*a*c
if (discriminant < 0){return("No real roots")}
positive <- (-b + sqrt(b^2 - 4*a*c)) / (2*a)
negative <- (-b - sqrt(b^2 - 4*a*c)) / (2*a)
print(paste("Answer: ",positive, negative))
}
quad(1,2,1)
## [1] "Answer: -1 -1"
quad(1,6,5)
## [1] "Answer: -1 -5"
quad(1,1,1)
## [1] "No real roots"