s <- 1
for (i in 1:12) {
s <- s * i
}
#Initialize an empty vector
v <- c()
for (i in 20:50) {
# if i is divisible by 5 then add to the vector
if (i %% 5 == 0) {
v <- append(v,i)
}
}
solve.quadratic <-function (a=1, b=-5, c=6) {
# Validate the inputs by checking if we'll encounter an imaginary number
if ( (b * b -4 * a * c) < 0 ) {
print( "There are no roots" )
return()
}
# Use the quadratic equation to find the roots
root1 <- (-b + sqrt( (b * b) - 4 * a * c)) / (2*a)
root2 <- (-b - sqrt( (b * b) - 4 * a * c)) / (2*a)
# Test if there is a decimal before printing
if ( root1 %% 1 == 0 ) {
print (sprintf ("x = [%d,%d]", root1, root2))
} else {
print (sprintf ("x = [%f,%f]", root1, root2))
}
}