factorial <- 1
for (i in 12:1) {
factorial = factorial * i
}
factorial
## [1] 479001600
numvec <-c(seq(20,50, by = 5))
numvec
## [1] 20 25 30 35 40 45 50
quadratic<- function(a, b, c){
discriminant = (b^2) - (4*a*c)
if (discriminant< 0)
{
return(print("No real roots!"))
}
else if (discriminant > 0) {
posroot <- (-b + sqrt(discriminant)) / (2*a)
negroot <- (-b - sqrt(discriminant)) / (2*a)
return(posroot)
return(negroot)
}
else {
x_intercept <- (-b)/ (2*a)
return(print("This quadratic equation has only one root. The root is ", x_intercept))
}
}
quadratic(1,6,5)
## [1] -1
I was unable to tweak program to print double negative roots!"]