#1 Write a loop that calculates 12-factorial
findfactorial <-function(n){
factorial <-1
if ((n==0)|(n==1))
factorial <-1
else{
for(i in 1:n)
factorial <- factorial * i
}
return (factorial)
}
findfactorial(12)
## [1] 479001600
#2 Show how to create a numeric vector that contains the sequence from 20 to 50 by 5
print(seq(20,50,5))
## [1] 20 25 30 35 40 45 50
#3 Create the function “quadratic” 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.
quadratic <- function(a,b,c){
x = (-b + (c(-1,1)*sqrt(b^2-4*a*c)))/(2*a)
return(x)
}
quadratic(1,-5, 6)
## [1] 2 3
quadratic(2, 4, 2)
## [1] -1 -1